I need to remotely execute a file on a network share. In searching I found a post
by tachyon that got me close. With his code I can remote execute any local file on the remote computer. However, when I try to remote execute a file on a network share I get access denied.
I am passing is the correct authentication but I wonder if it is not getting the credentials, or someting?
Is there a way to remote execute a file on a network share?
#!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") || ret
+urn 0;
my $serverConn = $locator->ConnectServer($server, "root/cimv2", $u
+sername, $password) || return 0;
return $serverConn;
}
###############
sub startProcess {
my ( $serverConn, $exe, $startupFolder ) = @_;
my $startClass = $serverConn->Get("Win32_Process") || return "Coul
+d Not Connect";
my $startConfig = $startClass->SpawnInstance_ ;
my $pid = Variant(VT_I4|VT_BYREF, 0);
my $retval = $startClass->Create( $exe, $startupFolder, undef, $pi
+d );
if ( 0 == $retval ) {return $pid;}
else {return "Could not start $exe errcode: " . decode_error($retv
+al);}
}
################
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]";
}