PHP WMI获取进程的所有者

时间:2017-01-24 17:10:37

标签: php windows wmi owner

我试图在使用WMI和PHP的Windows机器上获得少数进程的所有者。我用这篇文章编写了以下PHP代码: https://www.sitepoint.com/php-wmi-dig-deep-windows-php/ 我能够获得每个实例的属性,但我需要所有者。 而且我知道有一种方法" GetOwner"在Win32_Process类中,我应该获取所有者(和域或ReturnValue)。 我还尝试使用WMI Explorer和WMI代码生成器来获得语法如何工作的概念。

此代码应回显本地计算机上每个进程的所有者。 这是我的PHP代码:

<?php

    $pc = "localhost"; //IP of the PC to manage
    $WbemLocator = new COM ("WbemScripting.SWbemLocator");
    $WbemServices = $WbemLocator->ConnectServer($pc, 'root\\cimv2');
    $WbemServices->Security_->ImpersonationLevel = 3;

    $userlist = $WbemServices->ExecQuery ( "Select * from Win32_Process" );
        foreach ($userlist as $u) {
            $owner= $u->GetOwner;  //how to get the owner or domain here?
            var_dump($owner);
        }

几乎每个过程都会返回:

C:\ Users \用户名为myUsername \ test_wmi.php:22: INT(0)

这意味着成功完成,如此处所述:https://msdn.microsoft.com/En-US/library/aa390460.aspx

最后,我想做这样的事情,但是在PHP而不是在VB中: gallery.technet.microsoft.com/Monitor-Process-CPU-Pct-by-0f3a5a1c(对不起,我不允许发布两个以上的链接)

有没有人知道获取所有者的语法(而不是返回代码)?

谢谢!

1 个答案:

答案 0 :(得分:0)

最后我解决了这个问题:D

<?php

    $pc = "localhost"; //IP of the PC to manage

    $WbemLocator = new COM ("WbemScripting.SWbemLocator");
    $WbemServices = $WbemLocator->ConnectServer($pc, 'root\\cimv2');
    $WbemServices->Security_->ImpersonationLevel = 3;

    $userlist = $WbemServices->ExecQuery ( "Select * from Win32_Process" );
        foreach ($userlist as $u) {
            $owner= $u->ExecMethod_('GetOwner')->User;
            var_dump($owner);
        }