Hey guys, so im trying to convert a simple c# script into a perl script. All it really does is use the Win32_process namespace to execute a command on a remote server, the below c# will execute notepad.exe on a remote server, just for testing.
NOTE: I know psexec can do this, but id like to stay away from piping commands through that..
namespace WMISample
{
class Program
{
static void Main(string[] args)
{
string remoteMachine = "server";
ConnectionOptions connOptions = new ConnectionOptions(
+);
connOptions.Impersonation = ImpersonationLevel.Imperso
+nate;
connOptions.EnablePrivileges = true;
ManagementScope manScope = new ManagementScope(String.
+Format(@"\\{0}\ROOT\CIMV2", remoteMachine), connOptions);
manScope.Connect();
ObjectGetOptions objectGetOptions = new ObjectGetOptio
+ns();
ManagementPath managementPath = new ManagementPath("Wi
+n32_Process");
ManagementClass processClass = new ManagementClass(man
+Scope, managementPath, objectGetOptions);
ManagementBaseObject inParams = processClass.GetMethod
+Parameters("Create");
inParams["CommandLine"] = @"notepad.exe";
ManagementBaseObject outParams = processClass.InvokeMe
+thod("Create", inParams, null);
Console.WriteLine("Creation of the process returned: "
+ + outParams["returnValue"]);
Console.WriteLine("Process ID: " + outParams["processI
+d"]);
Console.ReadLine();
}
}
}