スクリプトの作成

このセクションではスクリプトが作成されます。 このスクリプトは、ローカル マシン上でメッセンジャー サービスが動作しているかどうかをチェックします。 スクリプトは、スクリプト デバッガーを使って開発され、機能のいくつかをデモします。

Function Main

' 使用する必要のあるオブジェクトの宣言

Dim wmi As Object

Dim objswbemobject As Object

' 必要な他の変数の宣言

Dim strComputer As String

Dim cr As String

strComputer = "127.0.0.1"

' キャリッジ リターン

cr = Chr(13) + Chr(10)

' wmi オブジェクトでフック

Set wmi = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

' フックが成功したことをチェック

If wmi is Nothing Then echo ("error1")

' wmi のサービス インスタンスを戻す

Set wmiinst=wmi.instancesof("Win32_Service")

' インスタンスが利用可能かどうかをチェック

If wmiinst is Nothing Then echo ("error2")

' 各インスタンスをループ

For Each objswbemobject In wmiinst

If objswbemobject.DisplayName = "Messenger" Then

echo("Service Name= ")

' サービスを表示

echo(objswbemobject.DisplayName+cr)

echo("Service Status= ")

' 状態を表示

echo(objswbemobject.State+cr)

If objswbemobject.State = "Running" Then main = true

If objswbemobject.State = "Running" Then main = true

End If

Next

End Function