我想在 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";
}
}
该脚本可以正常运行,但我每次都得到“零”回显字符串:
谁能告诉我是什么导致了这个问题以及如何解决它?谢谢!