I'm looking for a way to prevent windows from restarting/installing updates while my program is running. Currently, I've been setting a registry key which is located in:

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

called "AUOptions". I'm setting this to "2", however this doesn't seem to work in Vista, as my computer restarted last night. UAC is currently completely off. Any other ideas?

link|improve this question
Is the solution just for you personally on your PC only, or for your program which can be potentially running on other PCs? – Kurt W. Leucht Jul 30 '09 at 20:33
This code will run on over 5000 machines. – rwponu Jul 30 '09 at 20:39
This would be a good candidate question for the Beta Super User area. – Nazadus Jul 30 '09 at 20:44
Are you looking for a programattic method? If so, this belongs in stackoverflow (and shouldn't have been migrated...) – bdonlan Jul 30 '09 at 22:16
Yeah I am looking for a way to do it in C#. I don't really know why this was migrated. I guess the question is kind of in the middle anyways. – rwponu Jul 30 '09 at 22:19
feedback

migrated from stackoverflow.com Jul 30 '09 at 20:57

This question came from our site for professional and enthusiast programmers.

7 Answers

up vote 3 down vote accepted

You need to use a different registry setting for this:

HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU

Then set this to 1:

NoAutoRebootWithLoggedOnUsers

I've also put together a downloadable registry patch for this one if you want that instead.

link|improve this answer
feedback

Well, the way I have Windows Update configured on my computer, it will download the updates but won't actually install/restart them until I choose to do so (as I like to keep my computer on most of the time and don't like having to re-open everything I had opened before the computer restarted).

While potentially extreme, this would be a simple solution to your problem, albeit not a programmatic one.

link|improve this answer
I think that is actually what setting the registry key is supposed to do. – rwponu Jul 30 '09 at 20:40
feedback

IMO a better approach would be to study how your application can automatically re-start after windows has restarted.

I often left several Visual Studio instances, some explorer windows and some browsers running when I go home and when I'm back the following morning, all the applications are still running. So I think there might be a way to detects and automatically register the application to restart.

I think this might be more documented and easily implemented than trying to prevent windows from ever shutting down.

link|improve this answer
The problem is that users will have to log in again before the program would start again. That isn't acceptable. – rwponu Jul 30 '09 at 20:40
@rwponu I see... can you elaborate a little more on the situation and why this is the desired behavior? – chakrit Jul 30 '09 at 20:52
The program is an alarm clock. If the computer restarts due to windows update, obviously I'm pissing off quite a few users. – rwponu Jul 31 '09 at 1:22
feedback

I don't know if this is a windows forms app or not, but you can cancel a shutdown in the FormClosing event handler of a windows forms app thusly:

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (e.CloseReason == CloseReason.WindowsShutDown)
        {
            e.Cancel = true;
        }
    }

It's possible a windows update will override this, but a normal user shutdown will be prevented by this code (at least in XP).

link|improve this answer
if you do this, will the program still remain open? – rwponu Jul 30 '09 at 20:42
Yes, it cancels the shutdown cleanly and leaves the application running. – Michael McCloskey Jul 30 '09 at 20:56
feedback

There's a group policy setting in XP, Vista, and Win7. Note that gpedit.msc isn't installed on Vista home edition.

link|improve this answer
I want to have windows update disabled only while my program is running. It should start back up when the program is closed. – rwponu Jul 30 '09 at 20:44
feedback

It's not a good solution, but a possible one: just kill/stop the service.

you might also (at least this works on windows xp) change the policy settings using the gpedit.msc panel. don't know if editing the group policies can be done programatically as well...

regards

link|improve this answer
feedback

Run this process to stop windows update completely (at your own peril) "sc.exe stop wuauserv"

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.