Solved

Determine what user account a service is running under

Posted on 2009-07-02
3
737 Views
Last Modified: 2012-05-07
Hello I've attached the code I'm using below.  I just grab all the services, and iterate through them.  What I want to do as I iterate through them is this:
.
.
.
For Each mo In queryCollection
    'If userAccount = myUserAccount then
        'Change the password
    'else
        'do nothing

Next
.
.
.

How can I determine what account each service is running under?  Thanks,

Dim ReturnValue As String = String.Empty
        Dim strComputerName As String = "myComputerName"
        Try
 
            Dim query As ManagementObjectSearcher
            Dim queryCollection As ManagementObjectCollection = Nothing
            Dim co As ConnectionOptions
            Dim oq As System.Management.ObjectQuery
            Dim ms As System.Management.ManagementScope
            Dim mo As ManagementObject
            Dim strQuery As String
 
            strQuery = "SELECT * FROM Win32_Service"
            co = New ConnectionOptions
            ms = New System.Management.ManagementScope("\\" + strComputerName + "\root\cimv2", co)
 
            oq = New System.Management.ObjectQuery(strQuery)
            query = New ManagementObjectSearcher(ms, oq)
            Try
                queryCollection = query.Get()
            Catch e1 As Exception
 
            End Try
            For Each mo In queryCollection
 
            Next
 
 
        Catch ex As Exception
 
        End Try

Open in new window

0
Comment
Question by:BobBarker_99
  • 2
3 Comments
 
LVL 14

Expert Comment

by:shahprabal
ID: 24764567
0
 

Author Comment

by:BobBarker_99
ID: 24766935
I've already read through those pages.  I dont see anything there about determining what account a service is running under.  Am I missing something?
0
 

Accepted Solution

by:
BobBarker_99 earned 0 total points
ID: 24861327
http://www.codeproject.com/KB/cs/WMIforServices.aspx tells you what to pass into the searcher find all services for a specific user.  
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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