我有一个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);
}
}
}
这很好用,但是自从首次发布以来,我已经对我的应用程序进行了几次更新,但我的用户似乎没有收到它们。我的更新设置为:
在进一步测试后,如果我删除启动快捷方式,关闭程序,然后重新打开,则更新生效。
关于如何触发此自动启动程序的更新的任何想法?
答案 0 :(得分:0)
使用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 { }
}
}
}