How to retrieve ActivationUri after ClickOnce application has been restarted?

Joel Bloch 1 Reputation point
2021-05-26T07:45:48.57+00:00

I am doing the following code in a ClickOnce Application :

int APIENTRY WinMain(HINSTANCE hInstance,
                 HINSTANCE hPrevInstance,
                 LPSTR lpCmdLine,
                 int nCmdShow) {

   if (ApplicationDeployment::IsNetworkDeployed) {
      Uri^ uri = ApplicationDeployment::CurrentDeployment->ActivationUri;
      System::String^ queryString = uri->Query;
      if(mustUpdateRegistry(queryString)) {
         updateRegistry();
         Application::Restart();
      }
      doMain();
    }
}

The idea is the following: in same case I need to force the Win8RT, and I need to update the registry then restart the application. What mustUpdateRegistry and updateRegistry do is not that relevant to my problem.

My problem is, when the application restarts, ApplicationDeployment::CurrentDeployment->ActivationUri is null. To get the runtime version I have running on my Windows 10, I execute the following command line and get the following result:

Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -Name version -EA 0 | Where { $_.PSChildName -Match '^(?!S)\p{L}'} | Select PSChildName, version

v2.0.50727                       2.0.50727.4927
v3.0                             3.0.30729.4926
Windows Communication Foundation 3.0.4506.4926
Windows Presentation Foundation  3.0.6920.4902
v3.5                             3.5.30729.4926
Client                           4.8.03752
Full                             4.8.03752
Client                           4.0.0.0

I checked the documentation of Application.Restart, all the url and parameters should be identical after restarting. Do you know what I do wrong?

Thanks!

.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
326 questions
{count} votes

2 answers

Sort by: Most helpful
  1. ApplicGate 11 Reputation points
    2021-06-05T14:17:18.717+00:00

    One option is to save the Activation Uri in an Isolated Storage File of your App.

    0 comments No comments

  2. ApplicGate 11 Reputation points
    2021-06-06T17:39:34.17+00:00

    Extract of Visual Studio documentation:
    How to: Retrieve Query String Information in an Online ClickOnce Application

    When you use query string parameters, you must give careful consideration to how your application is installed and activated. If your application is configured to install on the user's computer from the Web or from a network share, it is likely that the user will activate the application only once through the URL. After that, the user will usually activate your application using the shortcut in the Start menu. As a result, your application is guaranteed to receive query string arguments only once during its lifetime. If you choose to store these arguments on the user's machine for future use, you are responsible for storing them in a safe and secure manner.

    --> If you restart your application (and do not activate it through the URL) ActivationUri is empty.
    This is not a bug, it is a feature!

    I hope this helps.

    0 comments No comments