接続中
グローバル管理者向け
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 フレームワークの場合