Exit Windows with a with a RunDLL call

You can Shutdown Windows 95/98 with a simple RunDLL call. The command must be set to:

%windir%\RunDll32.exe user,ExitWindows

%windir% is the path to your Windows folder (like C:\Windows). RunDll32.exe is a Windows program which may be used to call Windows API functions. Here we call the module user.dll which contains an API function ExitWindows. This function forces a shutdown under Windows 95/98. By the way, the function names within an API call are case sensitive.

Note: This trick won't work under Windows NT, because this operating system requires an authorization for shutdown (which can't be gained within a RundDLL32.exe call).

The code shown below uses this know how to shutdown Windows within a WSH script. The script is written in VBScript and it uses the Run method to execute the command.

'************************************************
' File:   RunExit.vbs (WSH sample in VBScript) 
' Author: Günter Born
'
' Uses the Run method to call the Windows 95/98
' ExitWindows API function.
'
' 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
'************************************************
' 
DIM WshShell

Set WshShell = WScript.CreateObject ("WScript.Shell")
If (MsgBox ("Shutdown Windows 95/98", vbYesNo + vbQuestion, _
    "WSH sample - by Günter Born") = vbYes) Then _
  WshShell.Run _
   "%windir%\RunDll32.exe user,ExitWindows", 1, -1

'*** End

Note: I have shown a technique using an ActiveX control to access the API-function ExitWindowsEx from WSH scripts in my WSH book Inside Windows Scripting Host, published by Microsoft Press Germany. The WSHExtend ActiveX-control is written in VB and may be downloaded from WSHExtend section of the Windows Scripting Host Bazaar). I have implemented the control only for Win 9x, because I was too lazy to dig into the privileges mumbo-jumbo of Windows NT (interested readers may find the updated version of the control that works also in Windows NT in Inside Windows Script Host, 2. Auflage, Micrsoft Press Deutschland). In Windows 2000 you can use WMI to shutdown the operating system.

Back

(c) G. Born