Rumus ShutDown Visual Basic 6.0

Shutdown restart logoff the local machine

The following API Declares and Constants can be used to force a PC to restart. Note, a demonstration routine can be found at the end of this post.

Private Declare Function ExitWindowsEx Lib “user32” (ByVal uFlags as Long, ByVal wReserved as Long) as Long

Private Const EWX_FORCE = 4 ‘Force any applications to quit instead of prompting the user to close them.
Private Const EWX_POWEROFF = 8 ‘Shut down the system and, if possible, turn the computer off.
Private Const EWX_LOGOFF = 0 ‘Log off the network
Private Const EWX_REBOOT = 2 ‘Perform a full reboot of the system
Private Const EWX_SHUTDOWN = 1 ‘Shut down the system

‘Purpose : Forces a machine shut down/logoff
‘Inputs : [lShutDownType] If unspecified, will reboot the machine else one of the above constants
‘Outputs : If successful returns a number other than zero
‘Notes : If this fails check the value of Err.LastDllError. If this is 1314 then
‘ the you do not have sufficient privileges to call this function.

Function MachineShutDown(Optional lShutDownType As Long = EWX_REBOOT) As Long
MachineShutDown = ExitWindowsEx(lShutDownType, 0&) ‘shut down the computer
End Function

‘Purpose : Forces a machine shut down/logoff
‘Inputs : N/A
‘Outputs : N/A
‘Notes : DOESN’T REQUIRE ANY PRIVILAGES

Sub MachineShutDown2()
Shell “rundll32.exe user32.dll, ExitWindowsEx”, vbHide
End Sub

‘Demonstration routine
Sub Test()
‘Forces the computer to reboot
‘When the EWX_FORCE flag is set, Windows does not send the messages WM_QUERYENDSESSION and
‘WM_ENDSESSION to the applications currently running in the system. This can cause the
‘applications to lose data. Therefore, you should only use this flag in an emergency.
Call MachineShutDown(EWX_FORCE Or EWX_REBOOT)
‘Forces the user to log off
Call MachineShutDown(EWX_LOGOFF)
‘Shuts the computer down (no restart)
Call MachineShutDown(EWX_SHUTDOWN)
‘Shuts the computer down and turns power off (if possible)
Call MachineShutDown(EWX_POWEROFF)
End Sub

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s