문제

ManagementScope scope = new ManagementScope( "\\\my_server\\root\\cimv2");
scope.Connect();

How do I run a batch file on my_server d:\tools? I have tried:

ManagementScope scope = new ManagementScope( "\\\my_server\\d\\tools"); 

But it doesn't seem to work.

도움이 되었습니까?

해결책

You need to use the Win32_Process class.

Here's an example of its use: http://msdn.microsoft.com/en-us/library/ms257364(v=vs.80).aspx

Example:

ManagementClass processClass = new ManagementClass(@"\\<remotecomputername>\root\cimv2:Win32_Process");
ManagementBaseObject inParams = processClass.GetMethodParameters("Create");

inParams["CommandLine"] = "calc.exe";
inParams["CurrentDirectory"] = @"c:\windows\system32";

ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top