【发布时间】:2014-09-12 09:00:08
【问题描述】:
当我尝试这个时得到 returnValue 9(找不到路径),我错过了什么?我正在尝试通过单击按钮运行 .bat 文件,下面的代码也不例外,但看起来找不到路径..
try
{
ManagementClass management = new ManagementClass("Win32_Process");
ManagementBaseObject inParams = management.GetMethodParameters("Create");
inParams["CommandLine"] = "test.bat";
inParams["CurrentDirectory"] = @"C:\test\"; //this is where test.bat is
var output = management.InvokeMethod("Create", inParams, null);
lblStatusResponse.Text = "" + output["returnValue"];
}
catch (Exception ex)
{
lblStatusResponse.Text = ex.ToString();
}
【问题讨论】:
-
您不使用
Process类的任何原因,例如stackoverflow.com/questions/181719/…? -
无法在我的服务器上运行...
标签: c# createprocess