2

I'm trying to determine whether or not WSUS manages the current machine by using the Windows Update Agent API. Currently, my code looks at all the services registered with Windows Update Agent.

    private static bool IsManagedByWSUS(WUApiNativeMethods.IUpdateSession3 session)
    {
        WUApiNativeMethods.IUpdateServiceManager serviceManager = session.CreateUpdateServiceManager();
        WUApiNativeMethods.IUpdateServiceCollection services = serviceManager.Services;
        foreach (WUApiNativeMethods.IUpdateService service in services)
        {
            // Indicates whether the service is registered with automatic updates
            var registeredWithAu = service.IsRegisteredWithAU();
            // Indicates whether the service is a managed service
            var isManaged = service.IsManaged();
            var name = service.Name().ToLower();
            if (registeredWithAu &&
                isManaged &&
                name.Contains("windows server update service"))
            {
                return true;
            }
        }
        return false;
    }

The problem is that I don't know whether or not checking for the name is reliable. I see that there is a service id field on the IUpdateService object that is a guid. I tested a couple of boxes, and it seems to always be 3da21691-e39d-4da6-8a4b-b43877bcb1b7.

How can I reliably check for WSUS?

Liang Wei
  • 21
  • 3

1 Answers1

0

you can check the registry file: HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate

shell command:

reg query "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"
dsaydon
  • 4,421
  • 6
  • 48
  • 52