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]"; }

In reply to Win32::OLE Remote Execution of a file on a network share. by slloyd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.