HippoMan
HippoMan

Reputation: 2328

Get name of Windows program's shortcut at run time?

In unix/linux, if a program is symlinked to another name and invoked under that other name, the name of the symlink, itself, is available under ARGV[0]. However, in Windows, if I have a shortcut to an executable and invoke it via the shortcut, ARGV[0] is the original program name, not the shortcut name.

Is there any way under Windows that I can get the program's shortcut name at run time?

For example, assume that in linux I have an executable called "origprog", and I do the following:

ln -s origprog newprog

If I run "./origprog", ARGV[0] is "./origprog", and if I run "./newprog", ARGV[0] is "./newprog".

However, under Windows, suppose I have a program called "origprog.exe" and I make a shortcut to it called "newprog.exe.lnk".

If I invoke "c:\path\to\origprog.exe", ARGV[0] is "c:\path\to\origprog.exe", and if I invoke "c:\path\to\newprog.exe.lnk", ARGV[0] is also "c:\path\to\origprog.exe". Is there any way in Windows at run time to find out that the program was actually invoked via "c:\path\to\newprog.exe.lnk"?

Thank you in advance.

Upvotes: 0

Views: 112

Answers (1)

MicroVirus
MicroVirus

Reputation: 5487

There are ways to do such, for instance when invoking the process programmatically using CreateProcess and friends; with these you can determine what the entire command line looks like, even omit the filename, such that argv[0] becomes the first argument what would 'normally' be argv[1].

If the same can be done with a shortcut, I do not know. You could always create a launcher executable and shortcut to that.

As for actually finding out if it was run using a shortcut without touching the shortcut itself, I highly doubt that's possible. Explorer reads the shortcut and invokes the designated program; there is no way for you to know why explorer launched your application.

Upvotes: 2

Related Questions