Skip to content

Instantly share code, notes, and snippets.

@keedi
Forked from aero/remote_exe.pl
Created April 25, 2013 06:59
Show Gist options
  • Save keedi/5458003 to your computer and use it in GitHub Desktop.
Save keedi/5458003 to your computer and use it in GitHub Desktop.
#!/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