BatchPatch currently provides functionality for retrieving from target computers the list of services that are set to ‘automatic’ but currently in the ‘stopped’ state. The reason this is valuable/convenient for most users is because after you reboot computers you frequently want to have a quick way to determine that all of the services that should be running are, in fact, running.
If a service is set to ‘automatic’ it generally should be running after Windows boots. However, unfortunately there are actually some cases where a service might be set to ‘automatic’ but isn’t always running. In these cases we may or may not actually care about the particular service in question.
For example, the following services on my computer are currently set to ‘automatic,’ but none of them are actually running at the moment:
Microsoft .NET Framework NGEN v4.0.30319_X86 Microsoft .NET Framework NGEN v4.0.30319_X64 Google Update Service (gupdate) Multimedia Class Scheduler Software Protection Skype Updater |
We have had some customers request the ability to create an exclusion list for the BatchPatch “Get stopped automatic services” action. The idea here is that you would be able to create a list of services that you don’t really care about, so that when you execute “Get stopped automatic services” it only lists the services that are NOT contained in the exclusion list. So if a really important ‘automatic’ service, like SQL Server, had not started after rebooting a computer, it would be easier to identify it if it weren’t buried in a list of other services that aren’t started, like the ‘Software Protection’ service, which is usually not started, even though it’s set to ‘automatic.’ We intend to provide this functionality in a future version of BatchPatch (EDIT: The feature was added 2015-07-22 and is available under ‘Tools > Settings > General > Exclusions list’). However, in the meantime while you are waiting for it, there is actually a very easy way to accomplish the same task in the current version of BatchPatch.
Sample script:
Download StoppedAutoServices.vbs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | 'Gets the list of services on a computer that are set to automatic and stopped but do not exist in the script's hardcoded list: arrayServiceExclusions. Cocobolo Software, LLC June 2015 'usage: cscript.exe StoppedAutoServices.vbs COMPUTERNAME 'the first argument from the command line is assigned to strComputer strComputer = WScript.Arguments(0) 'create an array containing the list of service display names to exclude from the check for stopped automatic services. arrayServiceExclusions = Array("Microsoft .NET Framework NGEN v4.0.30319_X86","Microsoft .NET Framework NGEN v4.0.30319_X64","Google Update Service (gupdate)","Multimedia Class Scheduler","Software Protection","Skype Updater") strStoppedAutoServicesList = "" intCounter = 0 on error resume next Err.Clear Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 'Get list of running services Set colService = objWMIService.ExecQuery("Select * from Win32_Service") For Each objService in colService If ((objService.StartMode = "Auto") And (objService.State = "Stopped")) Then boolIsServiceContainedInList = 0 'loop through our hardcoded list and compare For Each strServiceName in arrayServiceExclusions If objService.DisplayName = strServiceName Then boolIsServiceContainedInList = 1 End If Next 'if a service is set to automatic and in the stopped state and NOT contained in our hardcoded list, then add it to our final report and increment the counter If boolIsServiceContainedInList = 0 Then strStoppedAutoServicesList = strStoppedAutoServicesList & vbLf & objService.DisplayName intCounter = intCounter + 1 End If End If Next 'write the results list to the console WScript.Echo strStoppedAutoServicesList 'exit the script with the return value as the number of items in our list Wscript.Quit(intCounter) |
To integrate the StoppedAutoServices.vbs script into BatchPatch:
- Create a ‘Local process/command’ in BatchPatch. Select Actions > Execute local process/command > Create/modify local commands.
- Add the StoppedAutoService.vbs script to the grid.
Note, we use $computer as a parameter in the cscript.exe command. This tells BatchPatch to send the host name from the row that executes the script. This is what allows us to execute a script locally on the computer running BatchPatch to retrieve information from a remote computer. - Now we’re ready to execute the script. For the sake of this example, I have removed all but ‘Software Protection’ from the exclusion list hardcoded into the script as arrayServiceExclusions. The reason for this is to demonstrate what the output looks like when some ‘automatic’ services are found in the ‘stopped’ state. However, we will not see ‘Software Protection’ appear in our output since it remains in the arrayServiceExclusions. Highlight the target computers in the grid and then select Actions > Execute local process/command > Execute saved local commands > Get Stopped Automatic Services
- When the script completes a couple of seconds later, we can see that the ‘Exit Code’ value in the ‘All Messages’ column is equal to the number of stopped automatic services that were found, excluding (of course) the items hardcoded into the script arrayServiceExclusions, which in this instance was only ‘Software Protection.’ In the screenshot below I have revealed the cell contents for the first row, and we can see the 4 services that were found. If a machine is clear and no stopped automatic services are found, then the Exit Code will be 0, indicating that we do not need to further examine that computer.