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'")

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

   if skip = true then
      'msgbox svc.Name
      ' Service was not skipped. Do stuff here.
   end if
  • Without actaully plugging User's code into something, this looks pretty good. +1 to User-Who-Needs-A-Better-Name – gWaldo Sep 22 '10 at 19:59
  • nod Similar to how I was thinking I'd do it if I had to redo it in powershell. Thank you. – Aaron Wurthmann Sep 22 '10 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.