我想在Perl下使用Win32_Process :: GetOwner方法枚举所有正在运行的进程的名称和域名属性,我的代码如下所示:
use strict;
use warnings;
use Win32::OLE('in');
use Win32::OLE::Variant;
my $retval;
my $machine = ".";
my $outParam;
my $CLASS = "Winmgmts:{impersonationlevel=impersonate}!\\\\$machine\\root\\cimv2";
my $WMI = Win32::OLE->GetObject($CLASS) or die("GetObject:" . Win32::OLE->LastError());
my $process = $WMI->InstancesOf("Win32_Process");
my $vtName = Win32::OLE::Variant->new(VT_CY, VT_EMPTY);
my $vtDomain = Win32::OLE::Variant->new(VT_CY, VT_EMPTY);
foreach my $obj(in $process)
{
$retval = $obj->GetOwner($vtName, $vtDomain);
if($retval == 0){
print $vtName->Value() . "\t" . $vtDomain->Value() . "\n";
}
}
脚本可以正常运行,但我每次都得到“零”回显字符串:
谁能告诉我是什么导致了这个问题以及如何解决这个问题? 谢谢!
答案 0 :(得分:1)
似乎Karthik已经拥有code you're looking:
my $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\localhost\\root\\CIMV2");
my $sqry = "SELECT * FROM Win32_Process where Name = \"$processName\" ";`
似乎其他人也有同样的问题,其中Perl发出的状态代码为0而不是实际数据: http://code.activestate.com/lists/perl-win32-users/16230/