Creating a script
In this section, a script is created. This script checks if the messenger service is running or not on the local machine. The script is developed using the script debugger and demonstrates some of its features.
Example
Function main
'declare the objects we will need to use
Dim wmi As Object
Dim objswbemobject As Object
'declare other variables we need
Dim strComputer As String
Dim cr As String
strComputer = "127.0.0.1"
'carriage return
cr = Chr(13) + Chr(10)
'hook with the wmi object
Set wmi = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'check that hook was successful
If wmi is Nothing Then echo ("error1")
'return the services instance of the wmi
Set wmiinst=wmi.instancesof("Win32_Service")
'check to see that instance is available
If wmiinst is Nothing Then echo ("error2")
'loop true each instance
For Each objswbemobject In wmiinst
If objswbemobject.DisplayName = "Messenger" Then
echo("Service Name= ")
'display services
echo(objswbemobject.DisplayName+cr)
echo("Service Status= ")
'display state
echo(objswbemobject.State+cr)
If objswbemobject.State = "Running" Then main = true
If objswbemobject.State = "Running" Then main = true
End If
Next
End Function