Hello,
I am trying to execute following script at system startup from
SOFTWARE\Microsoft\Windows\CurrentVersion\Run. Now the problem is this script
does not have exit/end if as it is meant for monitoring due to this startup
is waiting for the script to end - which will never happen. If I run this
script from user login everything works fine - but when the user logs out the
script also gets terminated. I tried using batch file from within I called
the vbs file but the batch also gets stuck at the vbs prompt and does not
quit. I know I am missing something here but what?
The script which needs to be run....
----------------
Dim strComputerName
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService. _
ExecNotificationQuery("Select * from __instancemodificationevent " _
& "within 30 where TargetInstance isa 'Win32_Service'")
i = 0
Do While i = 0
Set objService = colServices.NextEvent
If objService.TargetInstance.State <> _
objService.PreviousInstance.State Then
'Wscript.Echo objService.TargetInstance.Name & " is " &
objService.TargetInstance.State & ". The service previously was " & _
'objService.PreviousInstance.State & "."
'Wscript.Echo objService.TargetInstance.Name
if ucase(objService.TargetInstance.Name)<>"WUAUSERV" then
if ucase(objService.TargetInstance.Name)<>"WINHTTPAUTOPROXYSVC" then
if ucase(objService.TargetInstance.Name)<>"NTMSSVC" then
if ucase(objService.TargetInstance.Name)<>"CREPSRV" then
Set oWshShell = CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
strComputerName = WshNetwork.ComputerName
'Wscript.Echo strComputerName
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "ServiceStatus@adventity.com"
objEmail.To = "ServerAdmin@adventity.com"
objEmail.Subject = "Service Status Changed on " & strComputerName
objEmail.Textbody = objService.TargetInstance.Name & " is " &
objService.TargetInstance.State & ". The service previously was " & _
objService.PreviousInstance.State & "."
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"advex01.corp.adventity.com"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End If
End if
End if
End if
End if
Loop
-------------------------------