Description: |
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;
}
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
| [reply] |
|
| [reply] |
|