PHP から WMI の実行

  サービス停止



  
<?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";

?>
  
















   SQLの窓    create:2007/01/12  update:2014/10/04   管理者用(要ログイン)





フリーフォントWEBサービス

SQLの窓WEBサービス

SQLの窓フリーソフト

写真素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ