Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
873 views
in Technique[技术] by (71.8m points)

windows - Query WMI remotely with PHP

My current code looks like this:

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" );
}

Where would I put the login credentials for the remote_server? I see that it would take a username and password, but I'm not sure how to implement that.

Any help would be appreciated.

Reference: http://us3.php.net/manual/en/class.com.php

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
<?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>
          ";

?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...