We help IT Professionals succeed at work.

VB6 - Check Windows Update Service Status

Wilder1626
Wilder1626 asked
on
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.
Comment
Watch Question

Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer
SILVER EXPERT

Commented:
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

BRONZE EXPERT

Author

Commented:
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


Software Tead Lead / Business Analyst / System Analyst / Data Engineer
SILVER EXPERT
Commented:
you're doing an exact match and we are passing the service name as a parameter, hence try use this instead:

Set colServices = objSWbemServices.ExecQuery("SELECT State FROM Win32_Service Where Name = '" & ServiceName & "'")

Open in new window

Explore More ContentExplore courses, solutions, and other research materials related to this topic.