Shutdown, Reboot, or Log Off a System (Win 9x, NT, and 2000).

Category:
System/API
Type:
Snippets
Difficulty:
Intermediate
Author:
Marty

Version Compatibility: Visual Basic 5

More information:
To shutdown, reboot, or logoff a machine in VB, you use the ExitWindowEx API function. In addition, if you are running NT or 2000, you need to call the AdjustTokenProvileges function first. This function encapsulates the necessary tasks (i.e., checking the OS and calling the AdjustTokenPrivileges function if necessary).

One of the Enum Values in the declarations, passed to the function, determines whether you log off, restart, or shutdown, and whether the shutdown is graceful (running applications are given a chance to to exit and possibly cancel the shutdown) or forced. See the comments within the code for more detail.


Instructions: Click the link below to download the code. Select 'Save' from the IE popup dialog. Once downloaded, open the .zip file from your local drive using WinZip or a comparable program to view the contents.

Download reboot.zip