Hello,
I need for a bigger script (1000 lines) the capability to run the same script on UNIX and WIN32.
As yet, I'm successfull with constructs like in the example. But now I have a problem with the function from the example. With "use Win32::OLE qw( in );", in the second line this example works fine, but not on UNIX ;-( With "require Win32::OLE qw( in );", like in the example, I get an error.
Somebody with an idea?
use strict;
#use Win32::OLE qw( in );
if ( $^O eq "MSWin32" ) {
require Win32::OLE qw( in );
my $test=&getWinProcessId("cmd.exe");
print "$test\n";
}
sub getWinProcessId {
# to call with &getWinProcessId(ProcName)
# returns the process id
# returns -1 if no process found
# returns -2 if WMI not available
my $ProcName=$_[0];
my $found=0;
my $Class = "Win32_Process";
(my $Machine = shift @ARGV || "." ) =~ s/^[\\\/]+//;
if( my $WMIServices = Win32::OLE-> GetObject(
"winmgmts:{impersonationLevel=impersonate,(security)}//$Machine" ) ) {
foreach my $Processes ( in( $WMIServices-> InstancesOf( $Class ) ) ) {
#print "$Processes->{Name}: $Processes->{ProcessId}\n";
if ( "$Processes->{Name}"=~/$ProcName/i ) {
$found=1;
return ($Processes-> {ProcessId});
}
}
return -1;
}
else
{
# WMI does not work
return -2;
}
}
Kind regards,
Walter Laub
_______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
