使用PHP远程查询WMI [英] Query WMI remotely with PHP
本文介绍了使用PHP远程查询WMI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我当前的代码如下:
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的登录凭据放在哪里? 我看到它将需要一个用户名和密码,但是我不确定如何实现.
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.
任何帮助将不胜感激.
参考: http://us3.php.net/manual/zh/class.com.php
推荐答案
<?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>
";
?>
这篇关于使用PHP远程查询WMI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文