当我尝试使用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();
}
答案 0 :(得分:2)
您可以使用完全限定的路径作为CommandLine [in]参数:
inParams["CommandLine"] = @"c:\test\test.bat";
CurrentDirectory [in]正在设置子进程的路径,而不是"路径"到蝙蝠文件。