<?php
$str = "winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2";
$obj = new COM($str);
$ret = $obj->ExecQuery( "Select * from Win32_OperatingSystem" );
print "<PRE>";
foreach( $ret as $key => $target ) {
print "{$target->Caption}\n";
print "{$target->CSName}\n";
print "$target->ServicePackMajorVersion";
print ".{$target->ServicePackMinorVersion}\n";
print "{$target->WindowsDirectory}\n";
print "{$target->SystemDirectory}\n";
}
print "\n";
# **********************************************************
# Spooler ( 停止 )
# **********************************************************
$Query = "select * from Win32_Service where Name = 'Spooler'";
$RunningServices = $obj->ExecQuery($Query);
foreach( $RunningServices as $target ) {
$ReturnCode = $target->StopService();
}
# 終了待ち
$Cnt = 0;
while ( 1 ) {
sleep( 1 );
$RunningServices = $obj->ExecQuery($Query);
foreach( $RunningServices as $target ) {
$Result = $target->State;
}
if ( $Result == "Stopped" ) {
print " -> Spooler Stopped";
break;
}
$Cnt++;
if ( $Cnt > 60 ) {
print " -> Timeout";
break;
}
}
print "</PRE>";
print "OK";
?>
|