连接中
针对全球管理员
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框架的