Raj Kumar
Raj Kumar

Reputation: 7136

How to run a ClickOnce application (.appref-ms) on a remote computer?

I am trying to launch a ClickOnce application via an .appref-ms shortcut on a remote machine using WMI, but cannot succeed. The below code works fine if I try to run notepad.exe.

ManagementPath pm = new ManagementPath(@"\\server\root\cimv2:Win32_process");
ManagementClass processClass = new ManagementClass(pm);

//Get an input parameters object for this method
ManagementBaseObject inParams = processClass.GetMethodParameters("Create");

//Fill in input parameter values
inParams["CommandLine"] = @"C:\Documents and Settings\Start Menu\Programs\New\New App.appref-ms";

//Execute the method
ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);

Upvotes: 4

Views: 7512

Answers (2)

Helen
Helen

Reputation: 97952

Try launching the .appref-ms shortcut via rundll32:

inParams["CommandLine"] = @"rundll32.exe dfshim.dll,ShOpenVerbShortcut ""C:\New App.appref-ms"";

Alternatively, instead of relying on the shortcut path, you could use the application deployment URL (you can see it by opening the .appref-ms file in a text editor):

inParams["CommandLine"] = @"rundll32.exe dfshim.dll,ShOpenVerbApplication http://github-windows.s3.amazonaws.com/GitHub.application";

Keep in mind that Win32_Process.Create cannot create interactive processes remotely.

Upvotes: 5

Aamir
Aamir

Reputation: 15576

What is the error that you are getting.

BTW, there seem to be two problems with the commandline path that you are using.

  1. Start Menu folder IMO is in C:\Documents and Settings\"Usernamehere"\StartMenu.
  2. I am not sure but I think that you can't run a program remotely which lies inside a user's profile. Try installing the program to some other location like your c:\program files and then try to call it.

Apart from that, if you mention the exact error you are getting, then it would be helpful to diagnose the problem.

Upvotes: 0

Related Questions