Created
May 12, 2016 21:09
-
-
Save vendettamit/81c37d818bf883a48f4abad7f6770ebe to your computer and use it in GitHub Desktop.
WMI Snippet to invoke a process on remote machine with privileges.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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