VBA to ShutDown PC

  • Thread starter Thread starter Phil Greenwood
  • Start date Start date
P

Phil Greenwood

Could someone point me at some VBA to shut down a local PC
after a certain time. I'm okay with the Application.OnTime
method. And I've found the C code for the "ExitWindowsEx"
function but I'm afraid it's beyond me to convert to VBA.

All help welcome - Thanks - Phil
 
Phil, the VBA for the C code you found.. :)


'In general section
Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
Private Declare Function ExitWindowsEx Lib "user32" _
(ByVal uFlags As Long, ByVal dwReserved As Long) As Long

Private Sub ShutDown()
Dim ret&
If MsgBox("Press Cancel to PREVENT Shutdown!", _
vbOKCancel + vbCritical + vbApplicationModal) = vbCancel Then End
'reboot the computer
'ret = ExitWindowsEx(EWX_FORCE Or EWX_REBOOT, 0)
'shutdown
ret = ExitWindowsEx(EWX_FORCE Or EWX_SHUTDOWN, 0)
End Sub


keepITcool

< email : keepitcool chello nl (with @ and .) >
< homepage: http://members.chello.nl/keepitcool >
 
Back
Top