[英]Process.Start() fails to open the exe
I'm trying to launch an application from c# code. 我正在尝试从C#代码启动应用程序。 Below is the code.. But the exe gives the error "Application has encountered a problem and needs to close. Sorry for the inconvenience".
下面是代码。.但是exe给出错误“应用程序遇到问题,需要关闭。对不起给您带来的麻烦”。
I'm passing the command values as 我将命令值传递为
command = "\"C:\\Program Files\\Nimbuzz\\Nimbuzz.exe\"";
code: 码:
private int ExecuteSystemCommand(string command)
{
procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = false;
proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
return proc.Id;
}
But the exe opens normally when opened from the desktop short cut. 但是从桌面快捷方式打开时,exe会正常打开。 I dont know whats wrong.
我不知道怎么了。 Please suggest.
请提出建议。
You must specify the EXE you want to execute. 您必须指定要执行的EXE。
Process.Start("cmd.exe", ...)
It would appear that these articles answer the question: 这些文章似乎回答了这个问题:
好吧,我刚刚发现,我需要在调用Process.Start()之前先设置工作目录。
Directory.SetCurrentDirectory("C:\\Program Files\\Nimbuzz\\");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.