创建脚本

在本节中将创建脚本。 该脚本将检查本地计算机上是否运行有信使服务。 该脚本使用脚本调试程序开发,演示了部分功能。

示例

函数 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")

'对每个实例进行 true 循环

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 函数