'************************************************************************************************
'File Name : Services_Checker.vbs
'Description : Connects to a Server and checks if the XXX services are running
'Author : Arumugam
'Date : 09/07/2008
'Version : 1.0
'************************************************************************************************
on error resume next
wscript.echo
wscript.echo vbcrlf & " Services Checker"
wscript.echo "***********************"
logFile=replace(wscript.scriptfullname,wscript.scriptname,"")&"\Services.log"
set FSO = createobject("scripting.filesystemobject")
set objLog = FSO.createtextfile(logfile)
'Get the User ID
Wscript.StdOut.Write "Please enter your user name ( eg: user123):"
strUser = Wscript.StdIn.ReadLine
strUser = "DOMAIN\"&strUser
'Get the Password
Set objPassword = CreateObject("ScriptPW.Password")
Wscript.StdOut.Write "Please enter your password(corp domain) :"
strPassword = objPassword.GetPassword()
Wscript.Echo
if len(struser)<>12 or len(strPassword)<>8 then
msgbox"Check your Login Credentials"
wscript.quit
end if
objLog.writeline "################################################################################"
objLog.writeline "EXECUTION STARTED AT : " & now & " BY : " & strUser & vbcrlf
wscript.echo "Checking Services on the Servers.Please wait..."&vbclrf
MonitorGAPBEE ("servername")
objLog.writeline "EXECUTION COMPLETED AT : " & now
objLog.writeline "################################################################################"
objLog.close
set objLog = Nothing
set FSO = Nothing
Public Function MonitorGAPBEE(strServer)
on error resume next
objLog.writeline "SERVER NAME:"& strServer
objLog.writeline "========================="
'Server to be checked
strComputer =strServer
'Connect to WMI of the Remote server
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer,"root\cimv2",strUser,strPassword)
'Check if connection is successful
if err.number <> 0 then
objLog.writeline "Not connected"
objLog.writeline "********************************************"
objLog.writeline "Error occurred" &vbcrlf& err.description
objLog.writeline "********************************************"
objLog.writeline "SCRIPT IS ENDING NOW"
objLog.writeline "################################################################################"
wscript.echo "Error occurred" &vbcrlf& err.description
wscript.quit
else
objLog.writeline "connected"
end if
wscript.echo "*****************************************************"
wscript.echo strComputer & " Connected"
wscript.echo "============="
'Query the WMI for services
Set colDisks = objSWbemServices.ExecQuery("Select * from Win32_Service")
if err.number <> 0 then
objLog.writeline "WMI Query Failed" & vbcrlf& err.description&vbcrlf
else
objLog.writeline "WMI Query - Success"&vbcrlf
end if
'Set the Flag
Service_Flag = TRUE
objLog.writeline "Checking for abc services"
objLog.writeline "========================="&vbcrlf
'Check each of the services
For Each objDisk in colDisks
Service_Name = objDisk.displayname
Service_Status = objDisk.state
'Check the status of abc services
if instr(Service_Name,"abc") <> 0 and Service_Status<>"Running"then
strService = strService&vbcrlf&Service_Name
Service_Flag = FALSE
do until len(Service_Name) = 45
Service_Name = Service_Name&" "
loop
wscript.echo Service_Name & vbtab & Service_Status
objLog.writeline Service_Name & vbtab & Service_Status
elseif instr(Service_Name,"ULZ") <> 0 and Service_Status="Running"then
do until len(Service_Name) = 45
Service_Name = Service_Name&" "
loop
wscript.echo Service_Name & vbtab & Service_Status
objLog.writeline Service_Name & vbtab & Service_Status
end if
Next
'Check the Flag and display the msg
if Service_Flag = TRUE then
objLog.writeline "All the ULZ services are running fine"
else
WSCRIPT.ECHO
WSCRIPT.ECHO "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
wscript.echo "Please check the following services"& strService
WSCRIPT.ECHO "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
WSCRIPT.ECHO
objLog.writeline "Following abc services are not running"
objLog.writeline "======================================"&strService
end if
'Destruct the used objects
Set colDisks=nothing
Set objSWbemServices = nothing
Set objSWbemLocator = nothing
objLog.writeline "**************************************************************"
end function
wscript.echo "Completed. Press any key to exit"
strUser = Wscript.StdIn.ReadLine
Monday, November 9, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment