#! /usr/bin/perl use warnings; use strict; use Win32::OLE; use Win32::OLE::Variant; my $server = shift(@ARGV) || '.'; $server =~ s|^[\\/]+||; my $class = "WinMgmts:{impersonationLevel=impersonate}!//$server"; my $wmi = Win32::OLE->GetObject($class) or die "Error: Couldn't connect to \\\\$server: " . Win32::OLE->LastError(); # get a Win32_Process class object my $process = $wmi->Get("Win32_Process") or die "Error: couldn't get the process list: " . Win32::OLE->LastError(); # create a BYREF variant so a COM object can modify its value and return it my $pid = Variant(VT_I4 | VT_BYREF, 0); if (0 == $process->Create(join(" ", @ARGV), undef, undef, $pid)) { print "Process created with PID $pid\n"; } # if else { print "Error: couldn't create process.\n"; }