Link to home
Start Free TrialLog in
Avatar of Wilder1626
Wilder1626Flag for Canada

asked on

VB6 - Check Windows Update Service Status

Hi

I would like to use a VB application to give me the Task Manager service "wuauserv" status (Windows Update). I would like to create a command button that will pull the status and add it to my Label1.

User generated image
How can i do that?

Thanks for your help.
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

try this:

Public Function GetServiceStatus(ServiceName As String) As String
    strComputer = "."
    Set objSWbemServices = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colServices = objSWbemServices.ExecQuery("SELECT State FROM Win32_Service Where Name = '" & ServiceName & "'")
    For Each objService In colServices
        GetServiceStatus = objService.State
        Exit For
    Next
End Function

Open in new window


to implement:

Dim ServiceStatus As String
ServiceStatus = GetServiceStatus("wuauserv")

Open in new window

Avatar of Wilder1626

ASKER

I just tried that way but no error, no status result. Am i doing something wrong?

Public Function GetServiceStatus(ServiceName As String) As String
    strComputer = "."
    Set objSWbemServices = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colServices = objSWbemServices.ExecQuery("SELECT State FROM Win32_Service Where Name like 'wuauserv%'")
    For Each objService In colServices
        GetServiceStatus = objService.State
        Exit For
    Next
End Function

Private Sub StatusWindowsUpdate_Click()
Dim ServiceStatus As String
ServiceStatus = GetServiceStatus("wuauserv")
End Sub


Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial