There is no inbuilt command-line way to force install of waiting updates before shutdown/reboot (I've heard rumor that it's in Windows 8, but haven't checked).
You're best bet is to create a script (VBS, PowerScript, or alike) which will perform the updates and then shut the system down.
For example:
' NAME : <wusforceupdate>
' AUTHOR : <Samuel lambert>
' COMMENT : <Find-Download-Install-reboot (with windows update system WUS)>
' www.wsus.info/forums/lofiversion/index.php?t5454.html
'Shutdown flags;
const nLog_Off = 0
const nForced_Log_Off = 4 '( 0 + 4 )
const nShutdown = 1
const nForced_Shutdown = 5 '( 1 + 4 )
const nReboot = 2
const nForced_Reboot = 6 '( 2 + 4 )
const nPower_Off = 8
const nForced_Power_Off = 12 '( 8 + 4 )
ShutdownOption = nForced_Reboot
'Monthly log;
dt = date() : nMonth = Year(dt)*1e2 + Month(dt)
sLogFile = "C:\WUSforceupdate-" & nMonth & ".log"
Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()
Set searchResult = _
updateSearcher.Search("IsInstalled=0 and Type='Software'")
Set File = CreateObject("Scripting.FileSystemObject")
Set LogFile = File.OpenTextFile(sLogFile, 8, True)
LogFile.WriteLine("***************************************************************")
LogFile.WriteLine( "START TIME : " & now)
LogFile.WriteLine( "Searching for updates..." & vbCRLF)
LogFile.WriteLine( "List of applicable items on the machine:")
For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
LogFile.WriteLine( I + 1 & "> " & update.Title)
Next
Set WshShell = WScript.CreateObject("WScript.Shell")
If searchResult.Updates.Count = 0 Then
LogFile.WriteLine( "There are no applicable updates.")
WshShell.popup "There are no applicable updates.",1
ShutDown(ShutdownOption) '<-- O P T I O N A L
Wscript.quit
End If
LogFile.WriteLine( vbCRLF & "Creating collection of updates to download:")
Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
For I = 0 to searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
LogFile.WriteLine( I + 1 & "> adding: " & update.Title )
updatesToDownload.Add(update)
Next
LogFile.WriteLine( vbCRLF & "Downloading updates...")
Set downloader = updateSession.CreateUpdateDownloader()
downloader.Updates = updatesToDownload
downloader.Download()
LogFile.WriteLine( vbCRLF & "List of downloaded updates:")
For I = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(I)
If update.IsDownloaded Then
LogFile.WriteLine( I + 1 & "> " & update.Title )
End If
Next
Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
LogFile.WriteLine( vbCRLF & _
"Creating collection of downloaded updates to install:" )
For I = 0 To searchResult.Updates.Count-1
set update = searchResult.Updates.Item(I)
If update.IsDownloaded = true Then
'WshShell.popup "installing..." & vbNewLine & update.Title,1
LogFile.WriteLine( I + 1 & "> adding: " & update.Title )
updatesToInstall.Add(update)
End If
Next
logFile.WriteLine( "Installing updates...")
Set installer = updateSession.CreateUpdateInstaller()
installer.Updates = updatesToInstall
Set installationResult = installer.Install()
'Output results of install
LogFile.WriteLine( "Installation Result: " & installationResult.ResultCode )
LogFile.WriteLine( "Reboot Required: " & installationResult.RebootRequired & vbCRLF )
LogFile.WriteLine( "Listing of updates installed " _
& "and individual installation results:" )
For I = 0 to updatesToInstall.Count - 1
LogFile.WriteLine( I + 1 & "> " & updatesToInstall.Item(i).Title _
& ": " & installationResult.GetUpdateResult(i).ResultCode )
Next
If installationResult.RebootRequired = -1 then
LogFile.WriteLine( "RebootRequired")
' <-- normally now you should call for a R E B O O T.....
End if
ShutDown(ShutdownOption) '<-- O P T I O N A L
LogFile.WriteLine( "STOP TIME : " & now)
LogFile.WriteLine("***************************************************************")
LogFile.Close
wscript.echo "Updates are installed"
Function ShutDown(sFlag)
wscript.sleep 600
Set OScoll = GetObject( _
"winmgmts:{(Shutdown)}").ExecQuery( _
"Select * from Win32_OperatingSystem")
For Each osObj in OScoll
osObj.Win32Shutdown(sFlag)
Next
End Function
It's the same.
Like you said, you can force a shutdown by holding down the power button for longer (approximately 4 seconds), but this is literally cutting the power. An ACPI-initiated shutdown is the same as one you call through software. Both ways, all applications running on the machine have to be informed of the pending shutdown, (possibly abort it, depending on the version of Windows), and close themselves and any files they have open gracefully. That all takes time.
Basically, what makes the magic happen in either case is a call to the ExitWindowsEx
function, which is part of the Windows API used by programmers.* If you specify the EWX_POWEROFF
flag, the system is shut down and the power is turned off. It is also possible to call that function with the EWX_FORCE
flag, which will do just what it sounds like—force a shutdown without giving running applications the ability to delay or cancel it. If you do that, shutdown will likely happen faster but it will not be a completely "clean" shutdown and is therefore dangerous.
The difference in behavior that you're seeing is probably due to way that the software shutdown is initiated. For example, when you execute shutdown.exe
, you can indicate a timeout value for when the shutdown request should be initiated. During this period, the pending shutdown can be cancelled by running shutdown.exe
again with the /a
flag (to abort a pending shutdown). 60 seconds is a pretty common value for this timeout period.
The rest of the difference is probably just perceptual.
* The fact that Windows is a multi-user operating system can make things somewhat more complicated. But that's getting beyond the point here. Any other method of initiating a shutdown (e.g., InitiateSystemShutdown
) is going to behave similarly.
Best Answer
Shutdown command on Start screen in Windows 8 does not perform the "real" shutdown:
It's called Hybrid Shutdown. It is done for quicker startup time: the system does not need to perform full boot process.
When you use
shutdown
command, the OS shuts down completely and goes to power off mode.This article "Windows 8: Fast Boot" provides detailed information on the old and new shutdown sequence.
To change the behavior of Shutdown button on Start screen,
Alternatively click Battery icon on the taskbar and then click More Power Options.
Clear this check box if you want "real" shutdown.
To change this setting, you may need to click Change settings that are currently unavailable link at the top of the page.