Getting initial shortcut in C #

Suppose I have an executable file, and when it is running, I want to know how it was launched. That is, I would like to know if it is launched by a shortcut or directly. Wherein:

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

I can get the path to the executable, but this is always the same, even if it starts with a shortcut.

Lets say that my executable file is named c: \ text.exe, and I run it directly, and then test = 'c: \ test.exe' If I create a shortcut, that is c: \ shortcut.lnk (for the purpose c: \ test.exe), I want the test to be "c: \ shortcut.exe", but this is "c: \ test.exe"

I strongly suspect that this is impossible, because the OS processes part of the shortcut, and the executable never sees the difference, but maybe someone has a creative idea?

+3
source share
2 answers

This will not work at all, but if you create a shortcut, you can add a command line parameter to identify it.

+2
source

Your suspicions are true when the operating system hides the mechanics from you.

You can get the process that started you . this will not help you distinguish whether you were launched from a link in the Start menu, and not by double-clicking in the Explorer window.

+1
source

Source: https://habr.com/ru/post/1738449/


All Articles