Home
.. About WSUS Wiki

RSS

WSUS
.. WSUS FAQ
.. WSUS on SBS
.. WSUS Troubleshooting
.. WSUS News Groups
.. Known WSUS Issues
.. WSUS Links
.. WSUS Wish List

WSUS Documents
.. WSUS Deployment Guide
.. WSUS Installation Guide
.. WSUS Release Notes
.. WSUS Best Practice

SUS
.. SUS FAQ
.. What Is SUS
.. SUS Troubleshooting
.. SUS Links
.. SUS Known Issues
.. SUS FAQ
.. What Is SUS
.. SUS Troubleshooting
.. SUS Links
.. SUS Known Issues

Wiki Community
.. Wiki Contributors
.. I Love WSUS
.. WSUS Wiki Diary
.. Wiki Statistics
.. To Do Page

Miscellaneous Stuff
.. Other Resources
.. Do You Know?

Site Meter


Terms of Use
Trademarks
Privacy Statement

 

Schedule Computers For Reboot


This is a royal pain, especially for servers. Automatic scheduling is not usually an option. After updates are installed, it would be helpful to be able to select a client, and specify a time for the reboot if desired.


Resolution for WUS RTM

Microsoft has indicated that this feature is NOT going to be included in WSUS version 1, but is under consideration for future versions.

Moved commented inside of the page so it can be edited and pruned.

From giggsman - 2005-01-13 2:12 AM      []

I am a System Administrator and I hope all update can do and ffinish at background automatically. However, after installation, I have no choice to hide the notification windows for restart windows. I think my client should not know what I am doing to reduce their confusing. I suggest the notification should not display once I choose "No auto-restart for scheduled Automatic Updates installations".

From Wizard - 2005-01-13 2:33 AM      []

I agree somewhat with you giggsman, however, with Windows 2000, and XP, most of my clients just lock their PCs when they leave at night.  Sometimes the PC does not get rebooted for several days.
 
This would not be good for important security patches, if you need to get everyone to reboot.
 
I think there are arguments on both sides, but the constant reboot warning slightly wins, as the need to reboot and apply patches is greater than the need to not disturb the users.

From helsby - 2005-02-09 9:03 AM      []

as a sysadmin user, you could do this with a copy of shutdown from the resource kit. I schedule our servers to reboot at 10pm after a windows update run has taken place during the day. Yes I know its not integrated into WUS but its fairly easy to do

From aenea - 2005-02-25 8:19 AM      []

Here's a script you can schedule that will download and install updates. It's heavily cribbed from an MSDN example.

var wusSession;
var wusSearcher;
var wusSearchResult;
var iCounter;
var wshShell;
var wusUpdate;
var wusDownloadCollection;
var wusDownloader;
var wusInstallCollection;
var wusInstaller;
var wusInstallerResult;
var oError;
var sEventText;
var sResultText;
var oWMIService;
var oOSSet;
var eOSSet;
var oOS;

var EVENT_ERROR = 1;
var EVENT_WARNING = 2;
var EVENT_INFORMATION = 4;
var RESULT_NOTSTARTED = 0;
var RESULT_INPROGRESS = 1;
var RESULT_SUCCEEDED = 2;
var RESULT_SUCCEEDEDWITHERRORS = 3;
var RESULT_FAILED = 4;
var RESULT_ABORTED = 5;

//create a shell object for event logging
wshShell = WScript.CreateObject("WScript.Shell");

//log the start of the script
wshShell.LogEvent(EVENT_INFORMATION, "Scripted updates install starting.");

//create a WUS update session
try {
 wusSession = WScript.CreateObject("Microsoft.Update.Session");
}
catch(oError) {
 wshShell.LogEvent(EVENT_ERROR, "Unable to create a WUS Session. Error " + oError.number + ". " + oError.message);
 wshShell.LogEvent(EVENT_WARNING, "Scripted updates install stopped.");
 WScript.Quit();
};

//create a WUS update searcher
try {
 wusSearcher = wusSession.CreateUpdateSearcher();
}
catch(oError) {
 wshShell.LogEvent(EVENT_ERROR, "Unable to create a WUS update searcher. Error " + oError.number + ". " + oError.message);
 wshShell.LogEvent(EVENT_WARNING, "Scripted updates install stopped.");
 WScript.Quit();
};

//search for uninstalled updates for this machine
try {
 wusSearchResult = wusSearcher.Search("IsInstalled = 0");
}
catch(oError) {
 wshShell.LogEvent(EVENT_ERROR, "Unable to search for updates. Error " + oError.number + ". " + oError.message);
 wshShell.LogEvent(EVENT_WARNING, "Scripted updates install stopped.");
 WScript.Quit();
};

//quit the script if there are no updates found for this machine
if (wusSearchResult.Updates.Count == 0) {
 wshShell.LogEvent(EVENT_INFORMATION, "No updates found.");
 wshShell.LogEvent(EVENT_INFORMATION, "Scripted updates install finished.");
 WScript.Quit();
}
else {
 //updates were found. Write out an event log detailing the found updates
 sEventText = wusSearchResult.Updates.Count + " uninstalled updates found:\n";
 for (iCounter = 0;iCounter < wusSearchResult.Updates.Count;iCounter++) {
  sEventText += wusSearchResult.Updates.Item(iCounter).Title + '\n';
 };  
 
 wshShell.LogEvent(EVENT_INFORMATION, sEventText);
};

//create a collection of updates to download from the WUS server
try {
 wusDownloadCollection = WScript.CreateObject("Microsoft.Update.UpdateColl");
}
catch(oError) {
 wshShell.LogEvent(EVENT_ERROR, "Unable to create a download collection. Error " + oError.number + ". " + oError.message);
 wshShell.LogEvent(EVENT_WARNING, "Scripted updates install stopped.");
 WScript.Quit();
};

//loop through the collection of required updates and add them
//to an update collection
for (iCounter = 0;iCounter < wusSearchResult.Updates.Count;iCounter++) {
 wusDownloadCollection.Add(wusSearchResult.Updates.Item(iCounter));
};

//create a WUS downloader
try {
 wusDownloader = wusSession.CreateUpdateDownloader();
}
catch(oError) {
 wshShell.LogEvent(EVENT_ERROR, "Unable to create a WUS download object. Error " + oError.number + ". " + oError.message);
 wshShell.LogEvent(EVENT_WARNING, "Scripted updates install stopped.");
 WScript.Quit();
};

//assign the collection of required updates to the downloader
wusDownloader.Updates = wusDownloadCollection;

//download the updates
try {
 wusDownloader.Download();
}
catch(oError) {
 wshShell.LogEvent(EVENT_ERROR, "Unable to download updates. Error " + oError.number + ". " + oError.message);
 wshShell.LogEvent(EVENT_WARNING, "Scripted updates install stopped.");
 WScript.Quit();
};

//create a collection of updates to install
try {
 wusInstallCollection = WScript.CreateObject("Microsoft.Update.UpdateColl");
}
catch(oError) {
 wshShell.LogEvent(EVENT_ERROR, "Unable to create an installer collection. Error " + oError.number + ". " + oError.message);
 wshShell.LogEvent(EVENT_WARNING, "Scripted updates install stopped.");
 WScript.Quit();
};

//loop through the collection of required updates and add them
//to the installation collection if they have been downloaded
for (iCounter = 0;iCounter < wusSearchResult.Updates.Count;iCounter++) {
 if (wusSearchResult.Updates.Item(iCounter).IsDownloaded == true) {  
  wusInstallCollection.Add(wusSearchResult.Updates.Item(iCounter));
 };
};

//create a WUS installer
try {
 wusInstaller = wusSession.CreateUpdateInstaller();
}
catch(oError) {
 wshShell.LogEvent(EVENT_ERROR, "Unable to create a WUS installer. Error " + oError.number + ". " + oError.message);
 wshShell.LogEvent(EVENT_WARNING, "Scripted updates install stopped.");
 WScript.Quit();
};

//set the updates to be installed to the WUS install collection
wusInstaller.Updates = wusInstallCollection;

//install the udpates
wusInstallerResult = wusInstaller.Install();

//log the installation results
sEventText = "Installation results:\n";
for (iCounter = 0;iCounter < wusInstallCollection.Count;iCounter++) {
 sEventText += wusInstallCollection.Item(iCounter).Title + ": ";
 
 switch (wusInstallerResult.GetUpdateResult(iCounter).ResultCode) {
  case RESULT_NOTSTARTED:
   sResultText = "Not started";
   break;
  case RESULT_INPROGRESS:
   sResultText = "In progress";
   break;
  case RESULT_SUCCEEDED:
   sResultText = "Succeeded";
   break;
  case RESULT_SUCCEEDEDWITHERRORS:
   sResultText = "Succeeded with errors";
   break;
  case RESULT_FAILED:
   sResultText = "Failed";
   break;
  case RESULT_ABORTED:
   sResultText = "Aborted";
   break;
  default:
   sResultText = "Unknown result";   
 };
 sEventText += sResultText + '\n'; 
};

wshShell.LogEvent(EVENT_INFORMATION, sEventText);

//reboot the machine, if necessary
if (wusInstallerResult.RebootRequired == true) {
 wshShell.LogEvent(EVENT_INFORMATION, "Scripted updates install finished. Initiating a reboot to complete update installation.");
 //reboot code
 oWMIService = GetObject("winmgmts:{(Shutdown)}");
 oOSSet = oWMIService.instancesof("win32_operatingsystem");
 eOSSet = new Enumerator(oOSSet);
 
 for (;!eOSSet.atEnd();eOSSet.moveNext()) {
  oOS = eOSSet.item();
  oOS.Win32Shutdown(6);
 };
}
else {
 wshShell.LogEvent(EVENT_INFORMATION, "Scripted updates install finished.");
};



Comments:

From Wonko - 1/31/06 11:43 AM

This is actually a JScript, so I'd recommend to use the extension .js, otherwise your interpreter might have a hard time trying to run it as a VBScript...

From rpaz - 1/8/06 5:52 PM

Hi Grey,

 Copy the text and save the file as .vbs

From Grey - 11/11/05 3:52 PM

What's the file extension for this script?


Last Modified 4/7/05 7:42 PM

Hide Tools