Solved

Function to highlight stopped services

Posted on 2006-06-19
5
152 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
Comment Utility


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
Comment Utility
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
Comment Utility
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
Comment Utility
this is vb6 code
0
 
LVL 1

Author Comment

by:john_123
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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

13 Experts available now in Live!

Get 1:1 Help Now