Skip to content

Instantly share code, notes, and snippets.

@vendettamit
Created May 12, 2016 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vendettamit/81c37d818bf883a48f4abad7f6770ebe to your computer and use it in GitHub Desktop.
Save vendettamit/81c37d818bf883a48f4abad7f6770ebe to your computer and use it in GitHub Desktop.
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);
scope.Connect();
//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 =
classInstance.GetMethodParameters("Create");
// 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