连接
对于全球管理员
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;
获取其他信息简单-只需替换instancesof('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 不工作!
Component_Object_Model
Win32 类
对于 Yii 框架