我正在尝试从位于远程计算机上的共享(指向另一台计算机)上的 ASP.NET 网站执行程序。这是配置的样子
网站服务器=>计算机A(带有指向的共享)=>计算机B(exe在这里)
如果我为 processName z:\tools\bin\myprogram.exe 传递以下参数,我会得到一个找不到路径的返回码。如果我为进程名称 \\computerB\tools\bin\myprogram.exe 传递以下参数,则会收到拒绝访问错误。
private static int CreateRemoteProcess(string serverName, string username, string password, string processName, params string[] arguments)
{
var connection = new ConnectionOptions
{
Username = username,
Password = password
};
var scope = new ManagementScope(@"\\" + serverName + @"\root\cimv2", connection);
using (var managementClass = new ManagementClass(scope,
new ManagementPath("Win32_Process"),
new ObjectGetOptions()))
{
var inputParams = managementClass.GetMethodParameters("Create");
if (arguments != null)
{
foreach (var param in arguments)
{
processName += " " + param;
}
}
inputParams["CommandLine"] = processName;
var outParams = managementClass.InvokeMethod("Create",
inputParams,
new InvokeMethodOptions());
outParams = managementClass.InvokeMethod("Create", inputParams, null);
var ret = Convert.ToInt32(outParams["ReturnValue"]);
return Convert.ToInt32(outParams["ProcessId"]);
}