【问题标题】:Application Updates Not Initiating应用程序更新未启动
【发布时间】:2019-01-24 15:44:49
【问题描述】:

我有一个 C# WinForms 应用程序,它在启动时使用用户启动文件夹中的快捷方式在任务栏中进行初始化:

private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        string startupFolder = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
        string shortcutAddress = startupFolder + @"\NotifyNinja.lnk";
        if (checkBox1.Checked)
        {
            if (!io.File.Exists(shortcutAddress))
            {
                WshShell shell = new WshShell();
                IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
                shortcut.Description = "A startup shortcut. If you delete this shortcut from your computer, Notify.exe will not launch on Windows Startup"; // set the description of the shortcut
                shortcut.WorkingDirectory = Application.StartupPath; /* working directory */
                shortcut.TargetPath = Application.ExecutablePath; /* path of the executable */
                shortcut.Save(); // save the shortcut 
            }
            else
            {
                io.File.Delete(shortcutAddress);
                WshShell shell = new WshShell();
                IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
                shortcut.Description = "A startup shortcut. If you delete this shortcut from your computer, Notify.exe will not launch on Windows Startup"; // set the description of the shortcut
                shortcut.WorkingDirectory = Application.StartupPath; /* working directory */
                shortcut.TargetPath = Application.ExecutablePath; /* path of the executable */
                shortcut.Save(); // save the shortcut 
            }
        }
        else
        {
            if (io.File.Exists(shortcutAddress))
            {
                io.File.Delete(shortcutAddress);
            }
        }
    }

这很好用,但是自从第一次发布我的应用程序以来,我已经对我的应用程序进行了几次更新,我的用户似乎没有收到它们。我的更新设置为:

  1. 申请开始后检查
  2. 每 7 天
  3. 不需要最低版本

经过进一步测试,如果我删除启动快捷方式,关闭程序并重新打开它,更新就会生效。

对如何触发此自动启动程序的更新有什么想法吗?

【问题讨论】:

  • checkbox1 被选中了吗?确保 checkbox1 真的是复选框 1 而不是复选框 2。
  • 是的,复选框运行良好。我担心的是启动功能会无意中禁用应用程序更新。
  • 如何发布您的应用程序?如果您使用 clickonce,您只需要配置这些功能
  • 是的,我确实使用 clickonce。我还启用了相关的更新功能。问题是他们似乎什么也没做。我对其他不会自动启动且更新工作正常的应用程序使用相同的配置。
  • 检查lnk文件的日期时间是否改变。如果它没有改变,那么代码中有错误。

标签: c# winforms updates startup shortcut


【解决方案1】:

在使用 Windows 自动启动应用程序时,似乎没有合适的方法来启动 clickonce 更新,所以我不得不以编程方式调用更新:

UpdateCheckInfo info = null;
        if (Directory.Exists(@"F:\..."))
        {
            if (ApplicationDeployment.IsNetworkDeployed)
            {
                ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

                try
                {
                    info = ad.CheckForDetailedUpdate();

                }
                catch { }
                if (info.UpdateAvailable)
                {
                    try
                    {
                        ad.Update();
                        Application.Restart();
                    }
                    catch { }
                }
            }
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多