2

I wonder what the "official" way is of running a application shortcut from within another application.
Like this:

string program = "application.exe";
Process.Start(program);

This won't work if application.exe is a shortcut.
The reason being, of course, that the actual filename of the application is appication.exe.lnk. Now Windows Explorer won't show the .lnk part (even when you have "Hide extensions for known filetypes" unchecked) while it does show when you do dir in a DOS box.

So what I came up with was this

string program = "application.exe";
if (!File.Exists(program)) program += ".lnk";
Process.Start(program);

but I keep wondering if there's a better way. This sounds... patchy. But my searches have come up empty. Nothing but explanations on how to create shortcuts and stuff.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Mr Lister
  • 45,515
  • 15
  • 108
  • 150
  • I think that the logic here is fine. If you're not happy with the implementation why don't you abstract it? It's likely that you want to check that the file exists before doing anything with it anyway so why not create a static function `Shortcut.Exists("application.exe");`. – User 12345678 Jun 07 '13 at 09:30
  • 1
    I can't really understand what you want to achieve.. if you know that you want to call a link > just call the link; if you want to call an application > call the application; if you want to call i.e. every application/application-shortcut in a directory you don't even have a problem because you know the correct file name when iterating over the files. – Felix Bayer Jun 07 '13 at 09:32
  • 1
    My problem is that according to Microsoft itself, there is not supposed to be that much difference between a shortcut and a real application. From a UI viewpoint, you can treat them both in the same way, run them without wondering if it's a shortcut at all etc. So I thought there would be no difference between running `application.exe` and a _shortcut_ to `application.exe`, especially since Microsoft does its best to hide the extra extension. – Mr Lister Jun 07 '13 at 09:37

1 Answers1

-2

This one works for me

 private void mainForm_Load(object sender, EventArgs e)
 {
           Process proc = new Process();
           proc.StartInfo.FileName = @"c:\d.lnk";
           proc.Start(); 
 }
Elerium
  • 30
  • 4