Avatar of Wilder1626
Wilder1626
Flag 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.

Windows update
How can i do that?

Thanks for your help.
Visual Basic Classic

Avatar of undefined
Last Comment
Ryan Chong

8/22/2022 - Mon
Ryan Chong

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

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
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61