C# 使用WMI在位于D驱动器中的远程计算机上运行exe
我在web服务器上托管了一个windows应用程序,在另一台服务器的D驱动器中放置了一个exe。现在我想从我的web服务器上运行那个exe,点击按钮使用WMI DLL。另外,我需要传递一些参数 我可以在远程计算机中打开记事本,但无法运行exeC# 使用WMI在位于D驱动器中的远程计算机上运行exe,c#,wmi,wmi-query,C#,Wmi,Wmi Query,我在web服务器上托管了一个windows应用程序,在另一台服务器的D驱动器中放置了一个exe。现在我想从我的web服务器上运行那个exe,点击按钮使用WMI DLL。另外,我需要传递一些参数 我可以在远程计算机中打开记事本,但无法运行exe string processPath = "path of exe"; var processToRun = new[] { processPath }; var connection = new ConnectionOptions(); conne
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);
string exec=“您的exe名称和参数(如果需要)”
如果有人知道,请帮我你收到错误信息了吗?你确定你的应用程序没有立即启动和崩溃吗?你只是在争论上有问题吗?关于这个问题没有足够的详细信息,人们无法可靠地帮助您回答这个问题-请尝试添加更多信息。我不知道如何提供exe的路径,因为当前代码会将我带到c://windows/system32这将在我的本地计算机上运行cmd。我想在另一台服务器上运行exe。然后使用类似PsExec的东西
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();