Determine status of operating system services

Posted on 2006-05-30
Last Modified: 2010-04-30
Hi. Wonder if anyone could point me in the direction of some (preferably VB6) code that would allow me to build a utility to check the status of a particular service running under Win 2000 Server or Win 2003 Server?

The specific service in question probably won't mean that much to most - Zylab Fax service if you're interested - however hopefully the solution will be a generic one that would allow me to check the status of other services as well, or at least tell me if the status is indeterminate.

Any help would be appreciated. Thanks.


Question by:YaHozna
    LVL 16

    Accepted Solution

    Try this out

    'Begin Copy
    'On Error Resume Next

    Dim strService As String
    strService = "Zylab Fax"

    'If you want to run this on a remote machine replace the
    'strComputer = "." with "RemoteCompName"
    strComputer = "."

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select name, state from Win32_Service" _
    & " where Name = '" & strService & "'", , 48)
    For Each objItem In colItems
        MsgBox objItem.Name & " is in the " & objItem.State & " state."

    'End copy

    Author Comment

    Hi and thanks. Looks like it might do the trick. I'll try it later today.



    Author Comment

    That worked perfectly. Many thanks.


    LVL 16

    Expert Comment

    Glad it worked for you!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    760 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

    8 Experts available now in Live!

    Get 1:1 Help Now