Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

End vbscript if field is left blank

Status
Not open for further replies.

cbsarge

IS-IT--Management
Jun 20, 2001
219
US
A simple little script to check if a service is running or not on a remote system. I'd like to be able to maybe pop up a message saying not to leave the field blank and then end or even better would be to pop the message and then return to the field that was left blank.

Thanks!
Code:
On Error Resume Next 
Dim strComputer
Dim strService
strComputer = InputBox("Enter the name of the Computer:","Service Checker") 
strService = InputBox("Enter the name of the Service:","Service Checker")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service Where Name = '" & strService & "'")
For Each objItem in colItems 
    Msgbox "Service Name: " & objItem.Name & VBNewLine & "State: " & objItem.State
Next

[!]The AutoSavers![/!] [2thumbsup]
 
Code:
On Error Resume Next
Dim strComputer
Dim strService
strComputer = InputBox("Enter the name of the Computer:","Service Checker")
strService = InputBox("Enter the name of the Service:","Service Checker")
If strComputer = "" Or strService = "" Then 
	MsgBox "One or more required fields where left blank. Script will now exit.", vbOKOnly + vbCritical, "Error"
	WScript.Quit
End If
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service Where Name = '" & strService & "'")
For Each objItem in colItems
    MsgBox "Service Name: " & objItem.Name & VBNewLine & "State: " & objItem.State
Next

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top