tags:

views:

519

answers:

2

Is it possible to find out whether your current .Net app has been launched using a shortcut or a Clickonce application reference (*.appref-ms) file? If so, how?

Some background: I am running into an issue using Microsoft Clickonce in which I cannot pass command line arguments to the application. It seems that this is the way the technology works by design. I was exploring different ways of passing this parameter; one of them was to have a set of different Clickonce Start Menu shortcuts.

A: 

I'm not sure what an "application reference file" is; do you mean like double-clicking the EXE file in Explorer or running the file from a command line?

There isn't any a priori way to detect how your program was started. The usual workaround is to configure the shortcut file to pass a parameter on the command line. Then, check for the existence of that parameter at run time. If you find it there, assume the program was started from a shortcut. The key to this approach is the fact that you can't include a parameter when double-clicking the EXE file in Explorer, so if you find a command-line parameter, you know the program wasn't started that way.

Rob Kennedy
While that sounds like a reasonable workaround, it doesn't account for the multiple ways you can shortcut to an app. Start menu, desktop shortcut, quicklaunch, recently used lists, and of course, opening the application by double clicking a document to "open with".
Soviut
That's easy. Configure a different command-line parameter for each shortcut or file association.
Rob Kennedy
+1  A: 

Try testing out the ApplicationDeployment.IsNetworkDeployed property. I know this will be true if it is a ClickOnce app but I'm not sure if it will be false in your situation.

Austin Salonen
It is true in all cases since I do want clickonce to launch the app.
siz
Thought it might be... What are you trying solve with arguments to a ClickOnce app?
Austin Salonen