Search code examples
c#shortcut

Run an application via shortcut using Process.Start()


Is there a way to run an application via shortcut from a C# application?

I am attempting to run a .lnk from my C# application. The shortcut contains a significant number of arguments that I would prefer the application not have to remember.

Attempting to run a shortcut via Process.Start() causes an exception.

Win32Exception: The specified executable is not a valid Win32 application

This is the code I am using.

ProcessStartInfo info = new ProcessStartInfo ( "example.lnk" );
info.CreateNoWindow = true;
info.UseShellExecute = false;
info.RedirectStandardError = true;
info.RedirectStandardOutput = true;
info.RedirectStandardInput = true;
Process whatever = Process.Start( info );

Solution

  • Setting UseShellExecute = false was the problem. Once I removed that, it stopped crashing.