简体   繁体   English

是否在Windows启动时强制ClickOnce应用程序更新?

[英]Forcing ClickOnce application update on Windows Startup?

I have a ClickOnce application that should automatically check for updates before the application starts. 我有一个ClickOnce应用程序,该应用程序启动前应自动检查更新。 If I start the application manually this also works perfectly. 如果我手动启动该应用程序,则也可以正常运行。

However I have also added a registry entry to start the application at windows startup and in this case the check for an update is not performed and the application starts just as if there would be no update - I guess because by the time the application starts the connection to the network drive on which the ClickOnce application installation is published is not yet established. 但是,我还添加了一个注册表项,以在Windows启动时启动应用程序,在这种情况下,不执行更新检查,并且应用程序启动时就像没有更新一样-我猜是因为在应用程序启动时尚未建立与发布ClickOnce应用程序安装所在的网络驱动器的连接。

As a workaround I tried to manually force the application in my code by calling this after my MainWindow is already loaded: 作为一种解决方法,我尝试在MainWindow已加载后通过调用此代码来手动强制应用程序:

private void checkforupdate() 
{
    try
    {

        ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

        if (ad.CheckForUpdate())
        {
            MessageBox.Show("Update available!");
            ad.Update();               
        }
    }
    catch { }
}

However for some reason this code still only triggers an update when I start the application manually, when it's started automatically on Windows start nothing happens. 但是由于某种原因,当我手动启动应用程序时,此代码仍仅触发更新,而在Windows上自动启动该应用程序时,则什么也没有发生。 The part of my code where I call checkforupdate is after there was already a few things loaded from the very same drive where the ClickOnce installation files are published so the connection must be established by then. 我的代码中称为checkforupdate的部分是在已经发布ClickOnce安装文件的同一驱动器中加载了一些东西之后,因此必须在那时建立连接。

Does anyone know what to do? 有谁知道该怎么办?

Ok, I found out that I was having a severe misunderstanding of how the update of a ClickOnce application works: In the registry entry which starts the program at Windows start-up I referred to the .exe file in the mysterious Users\\AppData\\Local\\Apps\\2.0.... folders - while this does work of course for starting the application itself it does not have anything to do with the update functionality itself. 好的,我发现我对ClickOnce应用程序更新的工作方式有严重的误解:在Windows启动时启动程序的注册表项中,我引用了神秘的Users \\ AppData \\ Local中的.exe文件。 \\ Apps \\ 2.0 ....文件夹-尽管这确实可以启动应用程序本身,但它与更新功能本身没有任何关系。 The update only happens when referring to ClickOnce Application reference (.appref-ms) Shortcut on the Desktop. 仅当在桌面上引用ClickOnce应用程序参考(.appref-ms)快捷方式时,才会进行更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM