6

私の現在のコードは次のようになります。

define ( 'CPU_NAME', 'remote_server' );
$obj = new COM ( 'winmgmts:{impersonationLevel=impersonate}//' . CPU_NAME . '/root/cimv2' );
if ( is_object ( $obj ) ){ 
     $process = $obj->execquery ( "SELECT * FROM Win32_Process" );
}

remote_server のログイン資格情報はどこに置くのですか? ユーザー名とパスワードが必要になることがわかりましたが、それを実装する方法がわかりません。

どんな助けでも大歓迎です。

参考: http: //us3.php.net/manual/en/class.com.php

4

4 に答える 4

15
<?php
    $obj = new COM ( 'winmgmts://localhost/root/CIMV2' );
    $fso = new COM ( "Scripting.FileSystemObject" );    
    $wmi_computersystem    =    $obj->ExecQuery("Select * from Win32_ComputerSystem");
    $wmi_bios              =    $obj->ExecQuery("Select * from Win32_BIOS");
    $processor             =    $obj->ExecQuery("Select * from Win32_Processor");
    $PhysicalMemory        =    $obj->ExecQuery("Select * from Win32_PhysicalMemory");
    $BaseBoard             =    $obj->ExecQuery("Select * from Win32_BaseBoard"); 
    $LogicalDisk           =    $obj->ExecQuery("Select * from Win32_LogicalDisk");


    foreach ( $wmi_computersystem as $wmi_call )
    {
        $model = $wmi_call->Model;
    }

    foreach ( $wmi_bios as $wmi_call )
    {
        $serial = $wmi_call->SerialNumber;
        $bios_version = $wmi_call->SMBIOSBIOSVersion;
    }

    foreach ( $processor as $wmi_processor )
    {
        $idprocessor = $wmi_processor->ProcessorId;
        $Architecture = $wmi_processor->Architecture;
        $Name = $wmi_processor->Name;
        $Version = $wmi_processor->Version;
    }
    foreach ( $PhysicalMemory as $wmi_PhysicalMemory )
    {
        $Capacity = $wmi_PhysicalMemory->Capacity;
        $PartNumber = $wmi_PhysicalMemory->PartNumber;
        $Name = $wmi_PhysicalMemory->Name;
    }

    foreach ( $BaseBoard as $wmi_BaseBoard )
    {
        $SerialNumber = $wmi_BaseBoard->SerialNumber;

    }
    foreach ( $LogicalDisk as $wmi_LogicalDisk )
    {
        $SerialNumberDisk = $wmi_LogicalDisk->VolumeSerialNumber;
        $FileSystem = $wmi_LogicalDisk->FileSystem;

    }

    echo "Bios version   : ".$bios_version."<br/>
          Serial number of bios  : ".$serial."<br/>
          Hardware Model : ".$model."<br/>
          ID-Processor : ".$idprocessor."<br/>
          Architecture-Processor : ".$Architecture."<br/>
          Name-Processor : ".$Name."<br/>
          Version-Processor : ".$Version."<br/>
          <hr>
          <hr>
          PhysicalMemory
          <hr>
          <hr>
          Capacity : ".$Capacity."<br/>
          Name : ".$Name."<br/>
          <hr>
          <hr>
          carte mere
          <hr>
          <hr>
          SerialNumber : ".$SerialNumber."<br/>
           <hr>
          <hr>
          disk
          <hr>
          <hr>
          SerialNumber : ".$SerialNumberDisk."<br/>
          FileSystem : ".$FileSystem."<br>
          ";

?>
于 2011-01-04T23:42:14.490 に答える
1
<?php
    $strComputer = "YOURREMOTEHOST";
    $objSWbemLocator = new COM ("WbemScripting.SWbemLocator");
    $objSWbemServices = $objSWbemLocator->ConnectServer($strComputer, "root\cimv2", "DOMAIN\USER", "Password");
    $objSWbemServices->Security_->ImpersonationLevel = 3;
    $obj = $objSWbemServices;
    $fso = new COM ( "Scripting.FileSystemObject" );

    //... insert your code here

    //... insert your code here
?>
于 2013-09-12T11:03:43.000 に答える
1

接続中

グローバル管理者向け

define("NAMECOMP", 'COMP1'); // COMP1 - name or ip of local or remote computer 
$WMI= new COM ( 'winmgmts:{impersonationLevel=impersonate}//'. NAMECOMP.'/root/cimv2' ); 

ログインとパスワード付きの場合

$objLocator = new COM("WbemScripting.SWbemLocator");
$objService = $objLocator->ConnectServer(
                'ComputerName', //name/ip remote/local comp
                "root\cimv2",
                'login', //login remote/local comp
                'password', //password remote/local comp
                "MS_409",
                "ntlmdomain: YourDomain" //domain remote/local comp
            );

情報を入手する

$CountCore=0;
foreach ($WMI->instancesof ( 'Win32_Processor' ) as $proc ) {
  ++$CountCore;
}
echo 'Count Core = ' . $CountCore; 

速度とソケットプロセッサの情報を追加

$CountCore=0;
foreach ($WMI->instancesof ( 'Win32_Processor' ) as $Processor) {
  ++$CountCore;
  $Speed=$Processor->CurrentClockSpeed;
  $Socket=$Processor->SocketDesignation;
}
echo 'count core = '.$CountCore;
echo 'speed = ' . $Speed. 'Mhz';
echo 'socket = '.$Socket; 

他の情報を簡単に取得 - インスタンスのクラスを置き換えるだけです ('Win32_Processor')

クラスの情報 WMI

コマンドを送る

if ((($_GET['Reboot']==1) OR ($_GET['Shutdown']==1))) { 
 
  define("NAMECOMP", 'COMP1');
          
  $WMI= new COM('winmgmts:{impersonationLevel=impersonate,(Shutdown)}//'. NAMECOMP.'/root/cimv2'); 
  
  foreach($WMI->instancesof('Win32_OperatingSystem') as $mp)  {
      if ($_GET['Reboot']==1) {
          $mp->Reboot; 
      }
      if ($_GET['Shutdown']==1) {
          $mp->Shutdown; 
      }
}

リンク:

WMI が機能しない!

コンポーネント_オブジェクト_モデル

Win32 クラス

Yii フレームワークの場合

于 2014-02-19T05:49:37.967 に答える