开发者

Getting the starting shortcut in c#

开发者 https://www.devze.com 2022-12-24 06:36 出处:网络
Lets say th开发者_如何学Cat I have an executable and when it is started I want to know how it\'s started. I.e. I would like to know if it is started with a shortcut or directly.

Lets say th开发者_如何学Cat I have an executable and when it is started I want to know how it's started. I.e. I would like to know if it is started with a shortcut or directly. With this:

string test = Environment.GetCommandLineArgs()[0];

I can get the path of the executable, but this is always the same, even if it's started by a shortcut.

Lets say my executable is named c:\text.exe and I start it directly, then test = 'c:\test.exe' If I create a shortcut i.e. c:\shortcut.lnk (with target c:\test.exe) I want test to be 'c:\shortcut.exe' but it is 'c:\test.exe'

I strongly suspect this to be impossible because the OS handles the shortcut part and the executable never can see the difference, but maybe someone has a creative idea?


This won't work in general, but if you are creating the shortcut, you could add a command line parameter to identify it.


Your suspicions are correct, with the operating system hiding the mechanics from you.

It is possible to get the process that started you, however. this won't help you differentiate whether you were started from a link in the start menu, vs. being doubled clicked on in the explorer window though.

0

精彩评论

暂无评论...
验证码 换一张
取 消