0

I'm using a select statement to show all services on a system currently set to Auto (automatic). The trouble is the list of service I do not want to see is growing. While still not larger than the list of services I do not want to see. I'm hoping that I can put all the services I do not want to see in an array and then check against the array during the select query (or afterwards if I have to) but so far I can't find an example where something similar is done and or I have PowerShell in my head and I can't think of how to do it vbscript

'Current Attempt
GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_Service where StartMode='Auto' and DisplayName<>'Performance Logs and Alerts' and DisplayName<>'SBSD Security Center Service' and DisplayName<>'TPM Base Services'")
Aaron Wurthmann
  • 283
  • 3
  • 8

1 Answers1

2

Doing this in a select query isn't really the best option, as there is no "IN" operator in WQL. The only way to do it, would be to build your select query dynamically, based on the array of excluded services.

I'd recommend doing it the latter way, by building an array of service names, retrieving ALL services with your select query, and then iterating over them. During the iteration, you'd have to check them against the array of excluded services.

Cheers, Trevor Sullivan

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

Excluded = Array("ccmexec", "wuauserv", "wudfsvc")

set svcs = GetObject("winmgmts:root\cimv2").ExecQuery("select * from win32_service where startmode = 'auto'")

for each svc in svcs
   skip = false
   for i = 0 to uBound(Excluded)
     if Excluded(i) =  svc.Name then skip = true
   next

   if skip = true then
      'msgbox svc.Name
   else
      ' Service was not skipped. Do stuff here.
   end if
next
Zoredache
  • 128,755
  • 40
  • 271
  • 413
Trevor Sullivan
  • 1,834
  • 3
  • 13
  • 19