Exit Windows using the Shell

If you have installed the Microsoft Internet Explorer 4.0/5.0 on your Windows 9X system, you have also a gate to access some shell function. One of this functions provides a way to invoke the Windows shutdown dialog or to suspend the computer. To access the Windows Shell object, you must retrieve a reference to the object using the following VBScript command:

Set Shell = WScript.CreateObject ("Shell.Application")

Afterward you can use the object variable Shell to access the methods and properties provided by the Shell object. Within this sample I use only two methods. The Suspend method forces Windows to invoke the suspend mode:

Shell.Suspend

If you like to invoke the Windows Shutdown dialog, you may use the following command:

Shell.ShutdownWindows

I have used this know how in the following VBScript program to access the Shell object.

'************************************************
' File:   WSHExit2.vbs (WSH sample in VBScript) 
' Author: Günter Born
'
' Demonstrates how to access the Shell object provided
' by the Internet Explorer to suspend Windows or 
' to invoke the Windows shutdown dialog box.
'
' In no way shall the author be liable for any
' losses or damages resulting from the use of this
' program. Use AS-IS at your own risk.
'
' The code is the property of the author. You may
' use the code and modify it, as far as this header
' remains intact. Further updates and other samples
' may be found on my site:
' http://www.borncity.de
'************************************************
'
Option Explicit

Dim Shell, Title

Title = "WSH sample - by Günter Born"

' create Windows Shell Application object
Set Shell = WScript.CreateObject ("Shell.Application")

' call Suspend-Method
If (MsgBox("Suspend Windows?", _
            vbYesNo + vbQuestion, Title) = vbYes) Then
 Shell.Suspend
End if

' invoke Shutdown Windows dialog
If (MsgBox("Open Shutdown Windows dialog?", _
            vbYesNo + vbQuestion, Title) = vbYes) Then
 Shell.ShutdownWindows
End if
'*** End

The Shell object provides many other methods and properties which are described in my WSH book Inside Windows Script Host, published by Microsoft Press Germany. The documentation of the Shell object may be found also in the Microsoft Developers Network (MSDN) - have a look at msdn.microsoft.com in the developers documentation (I forgot the exact location).

Back

(c) G. Born