Solved

Determine what user account a service is running under

Posted on 2009-07-02
3
738 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
[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
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

756 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