运行 远程计算机上的一个 exe 使用 WMI 放置在 D 盘中
Run a exe on remote computer placed in D drive using WMI
我在 Web 服务器上托管了一个 windows 应用程序,在另一台服务器的 D 盘中放置了一个 exe。现在我想 运行 使用 WMI DLL 单击按钮时来自我的 Web 服务器的那个 exe。另外,我需要传递一些参数。???
我可以在远程计算机上打开记事本,但无法运行 exe。
string processPath = "path of exe";
var processToRun = new[] { processPath };
var connection = new ConnectionOptions();
connection.Username =
connection.Password =
var wmiScope = new ManagementScope(String.Format("\\{0}\root\cimv2", "Server Name"), connection);
var wmiProcess = new ManagementClass(wmiScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());
var result = wmiProcess.InvokeMethod("Create", processToRun);
字符串执行 = "your exe name with argument if needed";
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo("cmd.exe");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardError = true;
psi.CreateNoWindow = true;
System.Diagnostics.Process proc =
System.Diagnostics.Process.Start(psi);
System.IO.StreamReader strm = proc.StandardError;
System.IO.StreamReader sOut = proc.StandardOutput;
System.IO.StreamWriter sIn = proc.StandardInput;
sIn.WriteLine("d:");//this line moves you to the d drive
sIn.WriteLine("cd "+Server.MapPath("Screenshot").ToString());//here screenshot is a my directory which containing the my .exe you can chamge it with yours
sIn.WriteLine(exec);//here your exe runs
strm.Close();
sIn.WriteLine("EXIT");
proc.Close();
string results = sOut.ReadToEnd().Trim();
sIn.Close();
sOut.Close();
我在 Web 服务器上托管了一个 windows 应用程序,在另一台服务器的 D 盘中放置了一个 exe。现在我想 运行 使用 WMI DLL 单击按钮时来自我的 Web 服务器的那个 exe。另外,我需要传递一些参数。???
我可以在远程计算机上打开记事本,但无法运行 exe。
string processPath = "path of exe";
var processToRun = new[] { processPath };
var connection = new ConnectionOptions();
connection.Username =
connection.Password =
var wmiScope = new ManagementScope(String.Format("\\{0}\root\cimv2", "Server Name"), connection);
var wmiProcess = new ManagementClass(wmiScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());
var result = wmiProcess.InvokeMethod("Create", processToRun);
字符串执行 = "your exe name with argument if needed";
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo("cmd.exe");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardError = true;
psi.CreateNoWindow = true;
System.Diagnostics.Process proc =
System.Diagnostics.Process.Start(psi);
System.IO.StreamReader strm = proc.StandardError;
System.IO.StreamReader sOut = proc.StandardOutput;
System.IO.StreamWriter sIn = proc.StandardInput;
sIn.WriteLine("d:");//this line moves you to the d drive
sIn.WriteLine("cd "+Server.MapPath("Screenshot").ToString());//here screenshot is a my directory which containing the my .exe you can chamge it with yours
sIn.WriteLine(exec);//here your exe runs
strm.Close();
sIn.WriteLine("EXIT");
proc.Close();
string results = sOut.ReadToEnd().Trim();
sIn.Close();
sOut.Close();