Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Win32::OLE Remote Execution of a file on a network share.

by slloyd (Hermit)
on Jun 23, 2004 at 20:12 UTC ( [id://369162]=perlquestion: print w/replies, xml ) Need Help??

slloyd has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: Win32::OLE Remote Execution of a file on a network share.
by JamesNC (Chaplain) on Jun 24, 2004 at 03:53 UTC
    try using runas on the shell that you are running the script from with the credentials of the user you want NTLM to use... I think that is how I solved a similar problem accessing a remote registry...
      runas prompts for a password and I do not see a way to script the password entry. Is there?
Re: Win32::OLE Remote Execution of a file on a network share.
by maa (Pilgrim) on Jun 24, 2004 at 07:00 UTC

    Remember that in a network environment you probably need:

    my $user="MyDomain\\Username";

    Or specify MyMachine\\Username if it is a local account on the workstation. I'm assuming you're using NT or newer here, not Win 9x

    HTH - Mark

Re: Win32::OLE Remote Execution of a file on a network share.
by Discipulus (Canon) on Jun 24, 2004 at 07:29 UTC
    why this code runs well against a w2k machine and against a 2k3 returns Dependent Services Running (what does it means? or well what services 2k3 need to started to accomplish the task?)?

    thanks in advance lor*

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://369162]
Approved by castaway
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-26 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found