Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|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. –  Russell Patterson Jul 30 '09 at 22:19
add comment

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 7 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.

share|improve this answer
add comment

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.

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

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).

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

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.

share|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. –  Russell Patterson Jul 31 '09 at 1:22
add comment

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

share|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
add comment

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.

share|improve this answer
add comment

Run this process to stop Windows Update completely (at your own peril):

sc.exe stop wuauserv
share|improve this answer
    
Your answer is without detail and hard to fully understand. Please consider revising your answer to provide more detail. For example, what does this process actually do? –  KronoS Jul 13 '12 at 4:25
    
I've made this a wiki. Please feel free to edit. –  Greg Jul 16 '12 at 13:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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