Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rebooting PC

Status
Not open for further replies.

jizviz

Programmer
Oct 13, 2002
26
US
I am trying to write a program that will reboot a PC prior to running a backup program but I have been unsuccessful getting the PC to reboot. My code looks like this:

Public Const EWX_FORCE = 4
Public Const EWX_LOGOFF = 0
Public Const EWX_REBOOT = 2
Public Const EWX_SHUTDOWN = 1

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

Sub Restart()
Dim test As Long

test = ExitWindowsEx(EWX_FORCE, 0)

End Sub

Can anyone tell me why this doesn't work? Thanks!!
 
Warning DO NOT USE THE EWX_FORCE TAG YOU COULD LOSE DATA!

You should be using ... EWX_REBOOT

But you need the SE_SHUTDOWN_NAME privilege ...

Just go to the previous link I posted, it explains everything.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top