Check All Services Which Set To Automatic Mode Are Running

Hi All,

This is my first post emoticons_wink.png  OK, straight to the point:

Attached template is based on VBScript and will check status of all services on the Windows based machines. If those services which set to automatic are not running script will increase "Statistic" counter. I have set threshold to CRITICAL = "1", as there is no real reason why AUTOMATIC service should not be running (there are some exceptions of course). The template will also report back names (Service Display Name) of those services which are set to automatic and not running. This is handled by "Massage" variable and will be visible in SAM, so, you can see in SolarWinds SAM all you need straight away.

You can also define exceptions. Well, this can be improved to make it bit more easier to manage. At the moment you will need to modify VBScript itself. Just open it and you will see straight away the line of code which you need to copy-pase. Add additional exception if you need to.

Thank you very much for using it,

Best of luck,

Alex

Parents
  • Alex,

    Any help making this work for one service? I can't code, I envy you. emoticons_sad.png

    Const wbemFlagReturnImmediately = &h10

    Const wbemFlagForwardOnly = &h20

    Dim MonitoredServer

    Dim arrComputers

    Dim StrComputer

    Dim objItem, objWMIService, colItems

    Dim Statistic

    'SCRIPT INPUT: ${IP}

    MonitoredServer = WScript.Arguments(0)

    For Each strComputer In arrComputers

    Const strSVCName = "erm8"

    arrComputers = Array(MonitoredServer)

    statistic = 0

    For Each strComputer In arrComputers

        Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

        Set colServices = objWMIService.ExecQuery("Select * from Win32_Service WHERE DisplayName = '" & strSVCName & "'")

           For Each objItem In colServices

               If objItem.StartMod = "Manual" Then

                 statistic = statistic + 1

            End If

        Next

              

                End If

            End If

          End If

       Next

    Next

  • What do you mean "for one service"? This script is specifically designed to handle all of them. If you just need one only - I suggest you use out-of-the-box solution to monitor services - it is called "Windows Service Monitor" when you build an application template and select add new component

  • Right. I'm doing that bu this guy wants to know if someone changes 1 service to manual.

    I have all the code in the world to do it but can't string it together properly. It's like putting my mom in the cockpit of a Lear jet. I would die to have ninja scripting skills.

  • You don't need ninja skills - Google has all you need emoticons_happy.png

    By the way, this is exactly the idea of this script - if you don't want this script to pick up any services - you just stick them to "manual" mode and job done. In your case however it is not a service you need to be monitoring, but your people. If "someone" has changed it to manual - I guess you need to find out who and why. There might have been a reason of doing so. I can see that in your above attempt you are trying to trigger an alert if your "erm8" service is set to manual... Hmmm... not the best approach. If I were you I would send a blanket email to technical team advising them that under any circumstances should automatic services be switched to manual, unless it has been approved by relevant team/engineers. Also, I am sure windows is logging an event every time you switch service to different mode - I guess you can use this event to trigger an alert on service mode change if needed.

    If you still want to proceed with your script, try to replace the following line with the below - as it is just one service - simply supply it in query as below:

    Set colServices = objWMIService.ExecQuery("Select * from Win32_Service WHERE DisplayName = 'erm8' ")

Comment
  • You don't need ninja skills - Google has all you need emoticons_happy.png

    By the way, this is exactly the idea of this script - if you don't want this script to pick up any services - you just stick them to "manual" mode and job done. In your case however it is not a service you need to be monitoring, but your people. If "someone" has changed it to manual - I guess you need to find out who and why. There might have been a reason of doing so. I can see that in your above attempt you are trying to trigger an alert if your "erm8" service is set to manual... Hmmm... not the best approach. If I were you I would send a blanket email to technical team advising them that under any circumstances should automatic services be switched to manual, unless it has been approved by relevant team/engineers. Also, I am sure windows is logging an event every time you switch service to different mode - I guess you can use this event to trigger an alert on service mode change if needed.

    If you still want to proceed with your script, try to replace the following line with the below - as it is just one service - simply supply it in query as below:

    Set colServices = objWMIService.ExecQuery("Select * from Win32_Service WHERE DisplayName = 'erm8' ")

Children
  • Thanks Alex. I will test. You are the OB1 to my Princess Leia.

  • emoticons_wink.png no problem

    By the way, in your script above it seems that you have too many "End If" clauses at the end. For every "For" there should be one "Next" at the end. For every "If" there may be "Then" somewhere in the middle, but there must be one closing "End If". Also you had a typo - "objItem.StartMode" not "objItem.StartMod"...

    So, after testing - here is what you get - working script below:

    =====================================

    Const wbemFlagReturnImmediately = &h10

    Const wbemFlagForwardOnly = &h20

    Dim MonitoredServer

    Dim arrComputers

    Dim StrComputer

    Dim objItem, objWMIService, colServices

    Dim Statistic, Message

    'SCRIPT INPUT: ${IP}

    MonitoredServer = WScript.Arguments(0)

    arrComputers = Array(MonitoredServer)

    Statistic = 0

    Message = "Hey, Scripting Guy ... erm8 is not Manual, but who knows - maybe someone has disabled it or it does not exist at all ... I need to make sure server access is properly secured and my engineers know what they are doing!"

    For Each strComputer In arrComputers

        Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

        Set colServices = objWMIService.ExecQuery("Select * from Win32_Service WHERE DisplayName = 'erm8'")

      For Each objItem In colServices

      If objItem.StartMode = "Manual" Then

      Statistic = Statistic + 1

      Message = "Oh my Gosh, erm8 has been set to Manual again!!! Whoever did it will get a massive slap when I find you!!!"

      End If

      Next

    Next

    WScript.Echo "Message: " & Message

    WScript.Echo "Statistic: " & CInt( Statistic )

  • Thanks a ton Alex.

    Its the hardest thing to cope with as a IT guy - to be able to fully understand code, but when it comes to stringing something together yourself, I get lost. I knew exactly what I needed, but........argh.

    Thanks again.