Windowsでサービス状態一覧を表示するコマンドがないのはなぜだろうか?(VBScript編)
Windowsでサービス状態一覧を表示するコマンドがないのはなぜだろうか?ではコマンドとバッチでやってみた。
Windows 2000のリソースキットに含まれてた「service.vbs」だと、もっといい感じに表示してくれた。
リソースキットの一部は、以下で公開されてるのだが「service.vbs」は見当たらない。残念。。。
ftp://ftp.microsoft.com/ResKit/win2000/
そこで、サービス状態の取得を使って、VBScriptで作ってみる。
上記のVBScript
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colRunningServices = objWMIService.ExecQuery _ ("Select * from Win32_Service") For Each objService in colRunningServices Wscript.Echo objService.DisplayName & VbTab & objService.State Next
実行結果
[D:\workspace\VBScript_SandBox]serviceinfo.vbs Microsoft (R) Windows Script Host Version 5.7 Copyright (C) Microsoft Corporation 1996-2001. All rights reserved. Alerter Running Application Layer Gateway Service Running Avira AntiVir スケジューラ Running Avira AntiVir Guard Running Apache2.2 Stopped Apple Mobile Device Running Application Management Stopped ASP.NET 状態サービス Stopped ATK Keyboard Service Running Windows Audio Running Background Intelligent Transfer Service Running Bonjour サービス Running Computer Browser Running Indexing Service Stopped ClipBook Stopped .NET Runtime Optimization Service v2.0.50727_X86 Stopped COM+ System Application Stopped ・ ・ ・
状態は取得できるのだが、表示がずれてしまう。
これだとバッチファイルと変わらない。
スペースパディングをするようにして表示を調整するように改良してみた。
改良したVBScript
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colRunningServices = objWMIService.ExecQuery _ ("Select Name,DisplayName,State from Win32_Service") For Each objService in colRunningServices packString = Left(objService.Name & Space(30), 30) Wscript.Echo packString & VbTab & objService.State & VbTab & VbTab & objService.DisplayName Next
実行結果
[D:\workspace\VBScript_SandBox]serviceinfo Microsoft (R) Windows Script Host Version 5.7 Copyright (C) Microsoft Corporation 1996-2001. All rights reserved. Alerter Running Alerter ALG Running Application Layer Gateway Service AntiVirSchedulerService Running Avira AntiVir スケジューラ AntiVirService Running Avira AntiVir Guard Apache2.2 Stopped Apache2.2 Apple Mobile Device Running Apple Mobile Device AppMgmt Stopped Application Management aspnet_state Stopped ASP.NET 状態サービス ATKKeyboardService Running ATK Keyboard Service AudioSrv Running Windows Audio BITS Running Background Intelligent Transfer Service Bonjour Service Running Bonjour サービス Browser Running Computer Browser CiSvc Stopped Indexing Service ClipSrv Stopped ClipBook clr_optimization_v2.0.50727_32 Stopped .NET Runtime Optimization Service v2.0.50727_X86 COMSysApp Stopped COM+ System Application ・ ・ ・
まぁこんなもんか。
VBScriptのヘッダー部分を消すなら、/nologoを付けて実行すればいい。
(表示しないように登録する方法があると思うのだが、まぁラップしたバッチすればいいか。)
[D:\workspace\VBScript_SandBox]cscript /nologo serviceinfo.vbs