Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run an application via shortcut using Process.Start()

Tags:

c#

shortcut

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 );
like image 589
user664939 Avatar asked May 26 '11 16:05

user664939


3 Answers

Could you post some code. Something like this should work:

Process proc = new Process();
proc.StartInfo.FileName = @"c:\myShortcut.lnk";
proc.Start();
like image 191
keyboardP Avatar answered Oct 23 '22 21:10

keyboardP


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

like image 13
user664939 Avatar answered Oct 23 '22 21:10

user664939


if your file is EXE or another file type like ".exe" or ".mkv" or ".pdf" and you want run that with shortcut link your code must like this.

i want run "Translator.exe" program.

Process.Start(@"C:\Users\alireza\Desktop\Translator.exe.lnk");
like image 1
Alireza Avatar answered Oct 23 '22 20:10

Alireza