[EMAIL PROTECTED] wrote:
>
> 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 warnings;
if ($^O eq 'MSWin32') {
require Win32::OLE;
import Win32::OLE qw(in);
(my $Machine = shift || Win32::NodeName ()) =~ s/^[\\\/]+//;
my $pid = getWinProcessId ($Machine, 'cmd.exe');
print "cmd.exe PID = $pid\n";
}
exit;
# my $pid = getWinProcessId ($Machine, $Process_Name)
# returns:
# process-id of first $Process_Name found on $Machine
# -1 if process found
# -2 if WMI not available
sub getWinProcessId {
my $Machine = shift;
my $ProcName = shift;
my $WMI = Win32::OLE->GetObject("WinMgmts://$Machine/root/cimv2") or return -2;
my $processes = $WMI->InstancesOf('Win32_Process') or return -1;
foreach my $Process (in $processes) {
if ($Process->{Name} =~ /$ProcName/i) {
return $Process->{ProcessId}; # should push on an array since
mult poss.
}
}
return -1;
}
__END__
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs