Question

I tried to check if Windows Update is enabled. I added a reference to c:\windows\system32\wuapi.dll on Windows 7 x64 Ultimate and wrote this code

using WUApiLib;
public Boolean IsWindowsUpdateEnabled()
{
    var updates = new AutomaticUpdatesClass();
    return updates.ServiceEnabled;
}

The code fails to build. I get the following error:

Error 1 The type 'WUApiLib.AutomaticUpdatesClass' has no constructors defined
Error 2 Interop type 'WUApiLib.AutomaticUpdatesClass' cannot be embedded. Use the applicable interface instead.
Error 3 'WUApiLib.AutomaticUpdatesClass' does not contain a definition for 'ServiceEnabled' and no extension method 'ServiceEnabled' accepting a first argument of type 'WUApiLib.AutomaticUpdatesClass' could be found (are you missing a using directive or an assembly reference?)

Was it helpful?

Solution

In your Visual Studio project References list, find the WUApiLib reference and change its "Embed Interop Types" to "False".

OTHER TIPS

Perhaps you could query the registry to see?

public string Read(string KeyName)
{
    // Opening the registry key
    RegistryKey rk = baseRegistryKey ;
    // Open a subKey as read-only
    RegistryKey sk1 = rk.OpenSubKey(subKey);
    // If the RegistrySubKey doesn't exist -> (null)
    if ( sk1 == null )
    {
        return null;
    }
    else
    {
        try 
        {
            // If the RegistryKey exists I get its value
            // or null is returned.
            return (string)sk1.GetValue(KeyName.ToUpper());
        }
        catch (Exception e)
        {
            // AAAAAAAAAAARGH, an error!
            ShowErrorMessage(e, "Reading registry " + KeyName.ToUpper());
            return null;
        }
    }
}

source

And the locations to look:

http://www.windowsnetworking.com/articles_tutorials/Registry-Keys-Tweaking-Windows-Update-Part1.html

HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU ...

The first of these keys is the AUOptions key. This DWORD value can be assigned a value of either 2, 3, 4, or 5. A value of 2 indicates that the agent should notify the user prior to downloading updates. A value of 3 indicates that updates will be automatically downloaded and the user will be notified of installation. A value of 4 indicates that updates should be automatically downloaded and installed according to a schedule. For this option to work, the ScheduledInstallDay and ScheduledInstallTime keys must also be set. I will talk more about those keys later on. Finally, a value of 5 indicates that automatic updates are required, but can be configured by end users.

Etc.

Though it might be different if the settings are done by the Group Policy.

More info here: http://support.microsoft.com/kb/328010

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top