使用Process.Start C#通过快捷方式运行应用程序
有没有办法通过C#应用程序的快捷方式运行应用程序?
我试图从我的C#应用程序运行.lnk。 快捷方式包含大量参数,我更希望应用程序不必记住。
尝试通过Process.Start运行快捷方式会导致exception。
谢谢
编辑:
例外是“Win32Exception”:“指定的可执行文件不是有效的Win32应用程序。”
这是(缩写)代码:
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 );
你能发一些代码吗? 像这样的东西应该工作:
Process proc = new Process(); proc.StartInfo.FileName = @"c:\myShortcut.lnk"; proc.Start();
设置UseShellExecute = false
是问题所在。 一旦我删除它,它就会停止崩溃。
如果你的文件是EXE或其他文件类型,如“.exe”或“.mkv”或“.pdf”,你想用快捷方式链接运行你的代码必须这样。
我想运行“Translator.exe”程序。
Process.Start(@"C:\Users\alireza\Desktop\Translator.exe.lnk");
如果您正在使用UseShellExecute = false并尝试启动批处理文件,请确保将.bat添加到文件名的末尾。 如果UseShellExecute = true,则不需要.bat。 这让我浪费了一个小时的工作……希望能拯救别人。