2017-01-24 7 views
0

私はWMIとPHPを備えたWindowsマシン上で少数のプロセスの所有者を取得しようとしています。この記事では、次のPHPコードを記述しています: https://www.sitepoint.com/php-wmi-dig-deep-windows-php/ すべてのインスタンスのプロパティを取得できますが、所有者が必要です。 そして、Win32_Processクラスにメソッド "GetOwner"があり、そこでは所有者(およびドメインまたはReturnValue)を取得する必要があることがわかりました。 また、WMI ExplorerとWMIコードジェネレータを使用して、構文の仕組みを理解しようとしました。PHP WMI getプロセスの所有者

このコードは、ローカルマシン上のすべてのプロセスの所有者をエコーし​​ます。ここ は私の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ここで説明するような完成(申し訳ありませんが、私は2つ以上のリンクを投稿することはできません)

誰にも戻りコードではなく所有者を取得する構文がありますか?

ありがとうございます!

答えて

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); 
     } 
関連する問題