#!perl use strict; use Win32::OLE; use Win32::OLE::Variant; my $exe='\\machine_b\path\exename.exe'; my $user="admin"; my $pass="admin"; my $server='machine_a'; my $c = connectServer( $server, $user, $pass ); if($c){ my $pid = startProcess( $c, $exe ); print "Pid: $pid\n"; } else{print "unable to connect to $server\n";} ############### sub connectServer { my ( $server, $username, $password ) = @_; $server ||= '.'; # localhost my $locator = Win32::OLE->new("WbemScripting.SWbemLocator") || return 0; my $serverConn = $locator->ConnectServer($server, "root/cimv2", $username, $password) || return 0; return $serverConn; } ############### sub startProcess { my ( $serverConn, $exe, $startupFolder ) = @_; my $startClass = $serverConn->Get("Win32_Process") || return "Could Not Connect"; my $startConfig = $startClass->SpawnInstance_ ; my $pid = Variant(VT_I4|VT_BYREF, 0); my $retval = $startClass->Create( $exe, $startupFolder, undef, $pid ); if ( 0 == $retval ) {return $pid;} else {return "Could not start $exe errcode: " . decode_error($retval);} } ################ sub decode_error { my %h = ( 1 => "Not Supported", 2 => "Access Denied", 3 => "Dependent Services Running", 4 => "Invalid Service Control", 5 => "Service Cannot Accept Control", 6 => "Service Not Active", 7 => "Service Request Timeout", 8 => "Unknown Failure", 9 => "Path Not Found", 10 => "Service Already Running", 11 => "Service Database Locked", 12 => "Service Dependency Deleted", 13 => "Service Dependency Failure", 14 => "Service Disabled", 15 => "Service Logon Failure", 16 => "Service Marked For Deletion", 17 => "Service No Thread", 18 => "Status Circular Dependency", 19 => "Status Duplicate Name", 20 => "Status Invalid Name", 21 => "Status Invalid Parameter", 22 => "Status Invalid Service Account", 23 => "Status Service Exists", 24 => "Service Already Paused", ); return $h{$_[0]} ? $h{$_[0]} : "Can't resolve error code $_[0]"; }