【发布时间】: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);
}
}
}
这很好用,但是自从第一次发布我的应用程序以来,我已经对我的应用程序进行了几次更新,我的用户似乎没有收到它们。我的更新设置为:
- 申请开始后检查
- 每 7 天
- 不需要最低版本
经过进一步测试,如果我删除启动快捷方式,关闭程序并重新打开它,更新就会生效。
对如何触发此自动启动程序的更新有什么想法吗?
【问题讨论】:
-
checkbox1 被选中了吗?确保 checkbox1 真的是复选框 1 而不是复选框 2。
-
是的,复选框运行良好。我担心的是启动功能会无意中禁用应用程序更新。
-
如何发布您的应用程序?如果您使用 clickonce,您只需要配置这些功能
-
是的,我确实使用 clickonce。我还启用了相关的更新功能。问题是他们似乎什么也没做。我对其他不会自动启动且更新工作正常的应用程序使用相同的配置。
-
检查lnk文件的日期时间是否改变。如果它没有改变,那么代码中有错误。
标签: c# winforms updates startup shortcut