VB Mania

Text Box: Previous Example
Text Box: Next Example
Text Box: VB-Mania Core

Shutdown Dialog

Information:

In this example, you will be able to use the function ExitWindowsEx to make a simple  shutdown dialog that can shutdown, restart or log off your computer.

Illustration:

 

What You Need?:

1. One Form named Form1

2. Three CommandButtons:

 

1. The first named Command1 (caption: "Shut Down")

2. The second named Command2 (caption: "Restart")

3. The third named Command3 (caption: "Log Off")

Private Declare Function ExitWindowsEx Lib "user32" (ByVal dwOptions As Long, ByVal dwReserved As Long) As Long

Private Const EWX_SHUTDOWN As Long = 1

Private Const EWX_LOGOFF As Long = 0

Private Const EWX_REBOOT As Long = 2

 

Function ShutDown()

ShutDown = ExitWindowsEx(EWX_SHUTDOWN, 0&)

End Function

 

Function Restart()

Restart = ExitWindowsEx(EWX_REBOOT, 0&)

End Function

 

Function LogOff()

LogOff = ExitWindowsEx(EWX_LOGOFF, 0&)

End Function

 

Private Sub Command1_Click()

ShutDown

End Sub

 

Private Sub Command2_Click()

Restart

End Sub

 

Private Sub Command3_Click()

LogOff

End Sub

Code:

 

Explanation:

ExitWindowsEx works on all Microsoft Windows Versions. As you see, by changing the parameter dwOptions, you can change the action from shutdown (dwOptions = 1), restart (dwOptions = 2), to logging off (dwOptions = 0).

Hint:

· You can use this in application that can shutdown the computer after a specific period of time or use it to shutdown other computer by sending a command over a Microsoft Winsock Control.

VB-Pedia:

ExitWindowsEx Logs off the interactive user, shuts down the system, or shuts down and restarts the system.

Shutdown Dialog

Sponsored Links

Google
 
Web vbmania2006.brinkster.net
planet-source-code.com support.microsoft.com