Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process.Start("IIS Manager.lnk") fails with "The system cannot find the file specified"

Tags:

c#

.net

windows

I'm launching the path C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools\IIS Manager.lnk via Process.Start, but it fails with The system cannot find the file specified.

The link shows up on a dir, so it exists.

Can it be permissions?

Notes:

  • The path is auto-discovered by iterating over the Start Menu directory.
  • I can launch it via explorer and command line.

Clarifications:

  • Code is as follows:

    public void Execute() { Process.Start(_shortcut.FullName);}

  • _shortcut is of type FileInfo

  • _shortcut.Exists is true, so the file can be found
  • replacing _shortcut.FullName with the explicit path @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools\IIS Manager.lnk" has the same effect.
  • This is a WPF app using Caliburn and MEF.
  • Running as Administrator has the same effect.

This here on the other hand seems to work:

    [Fact]
    public void TestIisManager()
    {
        var path = new FileInfo(@"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools\IIS Manager.lnk");
        Process.Start(path.FullName);
    }

It does seem to be a bit "environment" based.

Second clarification:

  • It seems to work in a Windows 7 x86 but not in a Windows 7 x64.
like image 694
Bruno Lopes Avatar asked Dec 10 '25 22:12

Bruno Lopes


2 Answers

I ran into this recently. Windows Forms based solution, VS2013, x64 machine. Process.Start() could not launch applications via .lnk file. Using process explorer, it seemed that the target specified in the .lnk file was resolving incorrectly to c:\program files (x86)... instead of c:\program files... I followed Bruno's excellent advice, but then again my Target was already marked as "AnyCPU".

After some head scratching, it turned out there's a new compiler flag in VS11+ called "Prefer 32-bit" that was checked by default. This was forcing the EXE output to be 32-bit even though my OS was 64-bit and platform was set to AnyCPU. After I unchecked and recompiled, the problem was fixed.

More reading at: http://blogs.microsoft.co.il/sasha/2012/04/04/what-anycpu-really-means-as-of-net-45-and-visual-studio-11/

like image 151
Sat Thiru Avatar answered Dec 12 '25 10:12

Sat Thiru


Found the issue.

The WPF application was compiled as x86 (all other dlls were compiled as AnyCPU), and when launching some executables or links in a 64 bit machine it failed.

Changing the "Platform Target" to AnyCPU fixes this.

like image 40
Bruno Lopes Avatar answered Dec 12 '25 12:12

Bruno Lopes