Get a list of remote services - / .net

Posted on 2007-08-12
Last Modified: 2013-11-26

Is there a way to get a list of all installed services (both disabled and enabled) on a remote computer using .net?

Thank you!
Question by:nahumba
    LVL 19

    Accepted Solution

    this writes output to a cvs file, but you can change the output to whatever
    you can use vbs or vb,net, or whatever for these scripts,.

    strComputer = "." 'pick a computer or setup in some array
    Const ForAppending = 8
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objLogFile = objFSO.OpenTextFile("c:\scripts\service_list.csv", _
        ForAppending, True)

    objLogFile.Write _
        ("System Name,Service Name,Service Type,Service State, Exit " _
            & "Code,Process ID,Can Be Paused,Can Be Stopped,Caption," _
            & "Description,Can Interact with Desktop,Display Name,Error " _
            & "Control, Executable Path Name,Service Started," _
            & "Start Mode,Account Name ")

    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colListOfServices = objWMIService.ExecQuery _
            ("Select * from Win32_Service")

    For Each objService in colListOfServices
        objLogFile.Write(objService.SystemName) & ","
        objLogFile.Write(objService.Name) & ","
        objLogFile.Write(objService.ServiceType) & ","
        objLogFile.Write(objService.State) & ","
        objLogFile.Write(objService.ExitCode) & ","
        objLogFile.Write(objService.ProcessID) & ","
        objLogFile.Write(objService.AcceptPause) & ","
        objLogFile.Write(objService.AcceptStop) & ","
        objLogFile.Write(objService.Caption) & ","
        objLogFile.Write(objService.Description) & ","
        objLogFile.Write(objService.DesktopInteract) & ","
        objLogFile.Write(objService.DisplayName) & ","
        objLogFile.Write(objService.ErrorControl) & ","
        objLogFile.Write(objService.PathName) & ","
        objLogFile.Write(objService.Started) & ","
        objLogFile.Write(objService.StartMode) & ","
        objLogFile.Write(objService.StartName) & ","

    Author Comment

    Thanks, I know this can be done with WMI, but I was wondering if there's a way to do this with .NET
    LVL 19

    Expert Comment

    you mena the openscmanager is what you are looking for?
    you want to make api calls? microsoft details step by step instructions

    Author Comment

    Hi weellio, well after looking at the links you've posted here, I think I'll do this using WMI :-)

    Seems much more simplier for my specific needs.

    Thank you!
    LVL 19

    Expert Comment

    it always is.  vbs and wmi are wonderful..  :)
    take a lok at powershell... it even gets easier, once you learn the lingo

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    761 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

    7 Experts available now in Live!

    Get 1:1 Help Now