Solved

Function to highlight stopped services

Posted on 2006-06-19
5
153 Views
Last Modified: 2010-04-30
Hi
I would like to write a utility which will check the status of the services on a server and identify any services which are marked as automatic but have stopped due to some reason or other.

Any pointers to get me going on this one?

Thanks
0
Comment
Question by:john_123
  • 3
  • 2
5 Comments
 
LVL 26

Accepted Solution

by:
EDDYKT earned 500 total points
ID: 16933827


Private Sub Command1_Click()
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service", , 48)
For Each objItem In colItems
    If objItem.StartMode = "Auto" And objItem.State = "Stopped" Then
        Debug.Print "AcceptPause: " & objItem.AcceptPause
        Debug.Print "AcceptStop: " & objItem.AcceptStop
        Debug.Print "Caption: " & objItem.Caption
        Debug.Print "CheckPoint: " & objItem.CheckPoint
        Debug.Print "CreationClassName: " & objItem.CreationClassName
        Debug.Print "Description: " & objItem.Description
        Debug.Print "DesktopInteract: " & objItem.DesktopInteract
        Debug.Print "DisplayName: " & objItem.DisplayName
        Debug.Print "ErrorControl: " & objItem.ErrorControl
        Debug.Print "ExitCode: " & objItem.ExitCode
        Debug.Print "InstallDate: " & objItem.InstallDate
        Debug.Print "Name: " & objItem.Name
        Debug.Print "PathName: " & objItem.PathName
        Debug.Print "ProcessId: " & objItem.ProcessId
        Debug.Print "ServiceSpecificExitCode: " & objItem.ServiceSpecificExitCode
        Debug.Print "ServiceType: " & objItem.ServiceType
        Debug.Print "Started: " & objItem.Started
        Debug.Print "StartMode: " & objItem.StartMode
        Debug.Print "StartName: " & objItem.StartName
        Debug.Print "State: " & objItem.State
        Debug.Print "Status: " & objItem.Status
        Debug.Print "SystemCreationClassName: " & objItem.SystemCreationClassName
        Debug.Print "SystemName: " & objItem.SystemName
        Debug.Print "TagId: " & objItem.TagId
        Debug.Print "WaitHint: " & objItem.WaitHint
    End If
Next


End Sub

0
 
LVL 1

Author Comment

by:john_123
ID: 16934089
Hi, am I supposed to be using the name of the computer in the strComputer variable?
This is Visual Basic Express 2005 and not working properly.
I am used to VB5 and VB6 not really Express - would this function be different in this environment?
0
 
LVL 1

Author Comment

by:john_123
ID: 16934101
I am also writing and testing this code on XP Pro rather than Server 2003 - would this cause problems?
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 16934452
this is vb6 code
0
 
LVL 1

Author Comment

by:john_123
ID: 16975040
I havejust found out that VB Express 2005 has built in components for performance monitoring and service control.
Many thanks anyhow. John.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

867 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

17 Experts available now in Live!

Get 1:1 Help Now