<?php
$pc = "127.0.0.1"; //IP of the PC to manage
$WbemLocator = new COM("WbemScripting.SWbemLocator");
$WbemServices = $WbemLocator->ConnectServer($pc, 'root\\CIMV2', '', '');
$WbemServices->Security_->ImpersonationLevel = 3;
$disks = $WbemServices->ExecQuery("SELECT Name FROM Win32_ComputerSystem");
foreach ($disks as $d) {
print( $d->Name);
}
PHP WMI获取主机名
这段PHP代码利用WMI(Windows Management Instrumentation)连接到指定的远程计算机(127.0.0.1),并查询Win32_ComputerSystem类来获取磁盘名称。代码中设置了安全级别为3以允许身份模拟,并通过循环遍历结果打印出每个磁盘的名称。
1505

被折叠的 条评论
为什么被折叠?



