?
Solved

Script to find services with login accounts

Posted on 2010-01-11
5
Medium Priority
?
665 Views
Last Modified: 2012-05-08
I'm hoping someone can help me get this to work. I want to list services using login accounts but I want to filter out localsystem, 'NT AUTHORITY\NetworkService' and 'NT AUTHORITY\LocalService'. The script works with only the localsystem filter but returns null is 'NT AUTHORITY\*" is added.
strComputer = "myComputer"
UserName = ""
Password = ""
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = SWBemlocator.ConnectServer(strComputer,"root\CIMV2",UserName,Password)
Set colItems = objWMIService.ExecQuery("Select * from Win32_service where (startmode='auto' OR startmode='manual') AND StartName <> 'LocalSystem'" & _
"AND StartName <> 'NT AUTHORITY\NetworkService' AND StartName <> 'NT AUTHORITY\LocalService'",,48)

For Each objItem In colItems
	 wscript.Echo objItem.name, objItem.State, objItem.StartName
Next

Open in new window

0
Comment
Question by:ScooterOc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 66

Expert Comment

by:johnb6767
ID: 26286299
This is similar to what I was asking at one time, and I got a great response from AmazingTech.....
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/XP/Q_24067885.html
Dont think it is exactly like you want, but it might suit your needs, wanted to offer it anyway.....
0
 
LVL 14

Accepted Solution

by:
BigBadWolf_000 earned 1500 total points
ID: 26286425
Try this....
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service where (startmode='auto' OR startmode='manual')")
For each objService in colServices 
    If objService.StartName = "LocalSystem" Then
        wscript.Echo objService.name, objService.State, objService.StartName
    End If

    If objService.StartName = "NT AUTHORITY\LocalService" Then
        wscript.Echo objService.name, objService.State, objService.StartName
    End If
    
    If objService.StartName = "NT AUTHORITY\NetworkService" Then
    wscript.Echo objService.name, objService.State, objService.StartName
    End If
    
Next

Set objWMIService = Nothing
Set colServices = Nothing

Open in new window

0
 
LVL 14

Expert Comment

by:BigBadWolf_000
ID: 26286448
add in credentials for login accounts....
0
 

Author Comment

by:ScooterOc
ID: 26287634
Thank you for the submittions, I took BigBadWolf's suggestion and moved part of the filter out of the query. I guess I must accept that WQL does not handle blank spaces within the constent very well. Unless someone can show me different, I'm going to consder this solved.


Set colItems = objWMIService.ExecQuery("Select * from Win32_service where (startmode='auto' OR startmode='manual')",,48)
For Each objItem In colItems
	 If UCASE(objItem.StartName) <> "NT AUTHORITY\NETWORKSERVICE" And UCASE(objItem.StartName) <> "LOCALSYSTEM" AND UCASE(objItem.StartName) <> "NT AUTHORITY\LOCALSERVICE" Then
	 	wscript.Echo objItem.name, objItem.State, objItem.StartName
	 End if
Next

Open in new window

0
 

Author Closing Comment

by:ScooterOc
ID: 31675658
The answer did not directly address the question but it did give me an idea to work around the problem.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question