Created
September 29, 2011 08:21
-
-
Save aero/1250271 to your computer and use it in GitHub Desktop.
Create process via Windows WMI
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
#!/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