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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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)
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)
ASKER
That is compiling with no errors, but its not rebooting....
What OS? Maybe you don't have privileges.
ASKER
Win XP Pro. I am local and domain admin...privileges should be fine.
ASKER
Desp, I do not quite understand that source, or how to use it. Have you used that before?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just a little typo in my previous post.
You have to call ExitWindowsEx(EWX_SHUTDOWN )
You have to call ExitWindowsEx(EWX_SHUTDOWN
Actually correct call to reboot must be:
ExitWindowsEx(EWX_FORCE Or EWX_REBOOT, 0)
ExitWindowsEx(EWX_FORCE Or EWX_REBOOT, 0)
ASKER
I ended up using Shutdown.exe via shell call.
Thanks for the help.
Thanks for the help.
ASKER