restart pc

shadowraven

Registered User.
Local time
Today, 11:07
Joined
May 14, 2002
Messages
75
Hi Guys,Gals can anyone have a look at this code and see where it is going wrong. I would like to be able to have a button which when clicked will restart the pc if needed.

Option Compare Database
Option Explicit

Private Sub Command0_Click()
If MsgBox("Your computer needs to be rebooted. Press OK to reboot " & _
"or Cancel to Abort.", vbOKCancel + vbQuestion, "Reboot?") = vbOK Then

Dim lngRes As Long

Private Const EWX_REBOOT As Long = 2
'Private Declare Function ExitWindowsEx Lib "user32" (ByVal dwOptions As Long, ByVal dwReserved As Long) As Long

Private Sub command1_Click()
lngRes = ExitWindowsEx(EWX_REBOOT, 0&)
End Sub
Else
Exit Sub
End If
 
The code you have here has several things that would keep it from working. But we'll ignore those.

ExitWindowsEX() only allows you to shut down the system if the permissions have been set to do so.

Goto the following website click on the API Index (found on the left side of the window) and goto "E" there is an article reference "How to Shut Down, Reboot, Log Off or Power Off " that gives an example of how to make this work.

http://www.mvps.org/vbnet/
 
Last edited:
Hi thanks for the reply but im not able to access that link here in school as rm safety net filters us out and I dont have a computer at home so any other sugestions wil be good.
 
Last edited:
This is from vbapi.com

-----------------------------------------------------------------------------
Declare Function ExitWindowsEx Lib "user32.dll" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

Platforms: Win 95/98, Win NT

ExitWindowsEx shuts down or reboots the user's computer. Of course, since the shutdown/reboot process will begin once the function is called, there won't normally be much left for your program to do. The function returns 0 if an error occured, or 1 if successful.

uFlags
One or more of the following flags specifying how to shut down or reboot the computer:
EWX_FORCE = 4
Force any applications to quit instead of prompting the user to close them.
EWX_LOGOFF = 0
Log off the network.
EWX_POWEROFF = 8
Shut down the system and, if possible, turn the computer off.
EWX_REBOOT = 2
Perform a full reboot of the system.
EWX_SHUTDOWN = 1
Shut down the system.
dwReserved
Reserved for future versions of Windows. Always set to 0.
Example:

' Reboot the computer, forcing any open programs to close
Dim retval As Long ' return value

retval = ExitWindowsEx(EWX_REBOOT Or EWX_FORCE, 0)
If retval = 0 Then Debug.Print "Reboot attempt failed."
-----------------------------------------------------------------------------

HopeThis Helps
Dave
 
This is a curiosty question it may be useful in future.
thanx for all replys
 

Users who are viewing this thread

Back
Top Bottom