Solved

Determine what user account a service is running under

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 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