Solved

Function to highlight stopped services

Posted on 2006-06-19
5
156 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

756 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