Skip to content

Instantly share code, notes, and snippets.

@aero
Created September 29, 2011 08:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aero/1250271 to your computer and use it in GitHub Desktop.
Save aero/1250271 to your computer and use it in GitHub Desktop.
Create process via Windows WMI
#!/usr/bin/env perl
#How to use -> perl remote_exe.pl hostname "cmd /c dir"
use 5.010;
use strict;
use warnings;
use Win32::OLE;
use Win32::OLE::Variant;
my ($strComputer, $strCommand) = @ARGV;
my $objWMIService = Win32::OLE->GetObject("winmgmts:{impersonationLevel=impersonate,(security)}//$strComputer\\root\\cimv2:Win32_Process");
my $intProcessID = Variant( VT_I4 | VT_BYREF, 0 );;
my $errReturn = $objWMIService->Create( $strCommand , undef, undef, $intProcessID );
given ($errReturn) {
when (0) { say "Command successfully completed " . "Process ID: " . $intProcessID; }
when (2) { say "Access Denied"; }
when (3) { say "INsufficient Privilege"; }
when (8) { say "Unknown Failure"; }
when (9) { say "Path not found"; }
when (21) { say "Invalid Parameter"; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment