Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Using WMI for create a remote Process on Win32

by Sniper (Scribe)
on Jun 19, 2001 at 14:11 UTC ( [id://89593]=CUFP: print w/replies, xml ) Need Help??

I use this Snippet for create remote Process on Win32
it is ok for simple process but you should see the WMI SDK
for complex process user rights dependants

David "Sniper" Rigaudiere

use strict; use Win32::OLE qw( in ); use Win32::OLE::Variant; usage if @ARGV < 2; if( my $Pid = RemoteExec( @ARGV ) ) { print "Process created with PID $Pid\n"; } else { print "Process not created\n"; } exit; ##################################################################### sub RemoteExec { my $Machine = shift; my $CommandLine = join " ", @_; my($CLASS, $WMI, $Process, $vPid); $Machine =~ s|^[\\/]+||; $CLASS = "WinMgmts:{impersonationLevel=impersonate}!//$Machine"; print "Trying to launch @_ on $Machine\n\n"; $WMI = Win32::OLE->GetObject( $CLASS ) or die "Unable to connect to \\\\$Machine :" . Win32::OLE->Las +tError(); $Process = $WMI->Get( "Win32_Process" ) or die "Unable to get a Win32_Process :" . Win32::OLE->LastErr +or(); $vPid = Variant( VT_I4 | VT_BYREF, 0 ); # $vPid (out) PID o +f the created Process if( 0 == $Process->Create( $CommandLine, undef, undef, $vPid ) ) { return $vPid; } else { return undef; } } ##################################################################### sub usage { my($ScriptName) = $0 =~ m/.*\\(.*)$/; print<<"USAGE"; Usage : $ScriptName [\\\\]COMPUTERNAME CommandLine Parameters example :$ScriptName COMPUTER1 NOTEPAD C:\\FooBar.txt USAGE exit; }

Replies are listed 'Best First'.
Re: Using WMI for create a remote Process on Win32
by Umlaut (Novice) on Jun 29, 2001 at 21:11 UTC
    Very interesting. Do you know of a way to transfer a command to that remote machine and then execute it? That is, without pre-installing FTP or some other service.
    I know this is possible -- psexec (www.sysinternals.com) and HP's OpenBackup allow for remote installs.


    Thanks, Umlaut

      I copy the files via the admin share \\COMPUTERNAME\C$ then i use the WMI to run it...

      David "Sniper" Rigaudiere

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-23 22:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found