[英]Start exe file on remote machine
I have a process a method that successfully stops the process. 我有一个过程成功停止该过程的方法。 But how can I start it?
但是我该如何开始呢? It is a .exe file that lays on the remote machines harddrive.
这是一个.exe文件,位于远程计算机的硬盘驱动器上。
var ui = new ImpersonateUser();
var processName = "notepad.exe";
object[] processArgs = { @"C:\\WINDOWS\notepad.exe" };
try
{
ui.Impersonate(Domain, _userName, _pass);
ManagementPath path = new ManagementPath
{
Server = "serverName",
NamespacePath = "\\ROOT\\CIMV2",
ClassName = "Win32_Process"
};
ManagementScope scope = new ManagementScope(path);
ManagementClass management = new ManagementClass(path);
var query = new SelectQuery("SELECT * from Win32_process WHERE name = '" + processName + "'");
using (var searcher = new ManagementObjectSearcher(scope, query))
{
foreach (ManagementObject process in searcher.Get())
{
process.InvokeMethod("Terminate", null); //This work
Thread.Sleep(3000);
management.InvokeMethod("Create", processArgs); //doesnt work. Why ?
}
}
}
How can I make the .exe start after I have shut it down? 关闭它后如何启动.exe?
You have a typo (D instead of T) in a program name. 您在程序名称中有一个错字(用D代替T)。 It should be noTepad.exe and not noDepad.exe Besides I suggest to check results returned by InvokeMethod In your case it returns 9 what means Path Not Found .
它应该是noTepad.exe而不是noDepad.exe另外,我建议检查InvokeMethod返回的结果。在您的情况下,它返回9,表示未找到路径 。 Here is a full list of codes.
这是代码的完整列表。
UPDATE 更新
If InvokeMethod returns 0 but you don't see a new instance of notepad on a remote machine it means that it was run in background. 如果InvokeMethod返回0,但是您在远程计算机上看不到记事本的新实例,则意味着该记事本在后台运行。 However, you should be able to see this new instance in Windows Task Manager.
但是,您应该能够在Windows Task Manager中看到此新实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.