Solved

Function to highlight stopped services

Posted on 2006-06-19
5
158 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

707 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