开发者

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 = tr开发者_开发问答ue;
info.RedirectStandardOutput = true;
info.RedirectStandardInput = true;
Process whatever = Process.Start( info );


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

Process proc = new Process();
proc.StartInfo.FileName = @"c:\myShortcut.lnk";
proc.Start();


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


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");


If you're using UseShellExecute = false and trying to launch a batch file make sure to add .bat to the end of the filename. You don't need .bat if UseShellExecute = true though. This made me just waste an hour of work... hoping to save someone else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜