Link to home
Start Free TrialLog in
Avatar of forrest321
forrest321

asked on

VB.NET force reboot

I need to be able to force reboots on Win 2k and XP pro machines using VB.NET.  Does anyone know how this is done?
SOLUTION
Avatar of Fahad Mukhtar
Fahad Mukhtar
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of forrest321
forrest321

ASKER

It says: Name "exitWindowsEx" is not declared.
Sorry it is a typo, missing s:

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

ExitWindowsEx 2, 0
Some refinements:

In Vb.net declaration could be simpler:
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

To ensure will reboot you can use:
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
ExitWindowsEx(EWX_FORCE Or EWX_REBOOT, 0)

That is compiling with no errors, but its not rebooting....
What OS? Maybe you don't have privileges.
Win XP Pro.  I am local and domain admin...privileges should be fine.
Desp, I do not quite understand that source, or how to use it.  Have you used that before?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just a little typo in my previous post.

You have to call ExitWindowsEx(EWX_SHUTDOWN)
Actually correct call to reboot must be:
ExitWindowsEx(EWX_FORCE Or EWX_REBOOT, 0)
I ended up using Shutdown.exe via shell call.

Thanks for the help.