C # - WMI InvalidOperationException beim Versuch, ein Skript auf einem entfernten Rechner laufen zu lassen
-
12-10-2019 - |
Frage
Ich versuche, ein Skript auf einem entfernten Rechner in der gleichen Domäne auszuführen, mit dem gleichen Benutzerkonto angemeldet sowohl für die Maschinen. Hinweis: das Skript auch auf noch einen anderen Rechner gespeichert ist.
Code
string prop = propertyName
object[] cmd = { String.Format("cscript \\\\machine\\script.wsf", envId, application) };
ManagementClass mc = new ManagementClass("\\\\" + prop + "\\root\\cimv2\\Win32_Process");
mc.InvokeMethod("Create", cmd);
Ausnahme
[InvalidOperationException: Operation is not valid due to the current state of the object.]
System.Management.ManagementObject.InvokeMethod(String methodName, Object[] args) +388806
Fazit
Ich bin neu in WMI verwenden, so dass ich nicht sicher bin, ob das, was ich falsch mache offensichtlich ist, obwohl ich umsah diesen Ausnahmetyp in vielen Situationen verwendet wird, und Schwierigkeiten habe, herauszufinden, was die eigentliche Frage ist, , so würde Hilfe sehr geschätzt.
Lösung 3
It turns out that the windows service hosting the process was not running under an account that had permission to execute on the target machine.
My mistake!
Andere Tipps
Your "\root\cimv2\Win32_Process" should be "\root\cimv2:Win32_Process"
Note the colon, this is what I use. Good luck!
I had the same issue.
result.InvokeMethod("GetOwner", ownerArgs)
The problem was that I was trying to execute that on an object I retrieved with the following WMI query.
SELECT ProcessId, ExecutablePath, CommandLine FROM Win32_Process
Changing it to SELECT * FROM Win32_Process
fixed it.
I could've probably, also, specifically requested Username and Domain.