Question

I am working on a project and need to automate disabling Windows Automatic Update using my C# code. I am not quite sure where to start. I have read about possibly using the Windows Update Agent API but am not sure. Any advice would be greatly appreciated. Thanks in advance.

Was it helpful?

Solution

There is a windows service that is responsible for performing the updates, you can stop this service with the following code:

ServiceController sc = new ServiceController("wuauserv");
try
{
    if (sc != null && sc.Status == ServiceControllerStatus.Running)
    {
        sc.Stop();
    }
    sc.WaitForStatus(ServiceControllerStatus.Stopped);
    sc.Close();
}
catch (Exception ex)
{                
    Console.WriteLine(ex.Message);
}

You will need:

  1. Add a reference to the proyect selecting "Add Reference" into Project Name then Add System.ServiceProcess
  2. Include using System.ServiceProcess; in your class
  3. Run your application or Visual Studio as Administrator

OTHER TIPS

You could possibly achieve that by changing the Registry. Have a look at this technet page (should apply to Win XP as well as some others): http://technet.microsoft.com/en-us/library/dd939844(v=ws.10).aspx (Key: NoAutoUpdate)

There are some Classes which Help you accessing the Registry within C#: http://msdn.microsoft.com/en-us/library/microsoft.win32.registry(v=vs.90).aspx

(Source: Google)

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