Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
WMI Snippet to invoke a process on remote machine with privileges.
ConnectionOptions connection = new ConnectionOptions() {
EnablePrivileges = true
connection.Username = "achoudhary";
connection.Password = "ggn@1212";
connection.Authority = "ntlmdomain:health";
ManagementScope scope = new ManagementScope(
"\\\\7vmdev038\\root\\CIMV2", connection);
//var objStartup = scope.Get("Win32_ProcessStartup");
//var objConfig = objStartup.SpawnInstance_;
//objConfig.ShowWindow = SW_NORMAL;
ManagementClass classInstance =
new ManagementClass(scope, new ManagementPath("Win32_Process"), new ObjectGetOptions());
// Obtain in-parameters for the method
ManagementBaseObject inParams =
// Add the input parameters.
inParams["CurrentDirectory"] = @"C:\temp";
inParams["CommandLine"] = @"C:\temp\Check.bat"; //"C:\\eVital_Builds\\Utilities\\BulkTimesheetReader.exe";
//inParams["ProcessStartupInformation"] = "";
// Execute the method and obtain the return values.
ManagementBaseObject outParams =
classInstance.InvokeMethod("Create", inParams, null);
// List outParams
Console.WriteLine("Out parameters:");
Console.WriteLine("ProcessId: " + outParams["ProcessId"]);
Console.WriteLine("ReturnValue: " + outParams["ReturnValue"]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.