Solved

Determine what user account a service is running under

Posted on 2009-07-02
3
735 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
Comment Utility
0
 

Author Comment

by:BobBarker_99
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now