Run application via shortcut using Process.Start C

2019-01-15 08:35发布

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.

Thanks

EDIT:

The exception is a "Win32Exception": "The specified executable is not a valid Win32 application."

Here is the (abbreviated) code:

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

标签: c# shortcut
4条回答
Fickle 薄情
2楼-- · 2019-01-15 08:45

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

查看更多
混吃等死
3楼-- · 2019-01-15 08:46

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");
查看更多
ゆ 、 Hurt°
4楼-- · 2019-01-15 08:52

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

Process proc = new Process();
proc.StartInfo.FileName = @"c:\myShortcut.lnk";
proc.Start();
查看更多
老娘就宠你
5楼-- · 2019-01-15 09:05

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.

查看更多
登录 后发表回答