You know how you can hold down shift while you restart, and it will do a "soft" reboot, by only restarting windows? I want to do that in code, any ideas?
Printable View
You know how you can hold down shift while you restart, and it will do a "soft" reboot, by only restarting windows? I want to do that in code, any ideas?
here's an answer, compliments of Yonatan:
Try this:
First, put the following code in a module.
Option Explicit
Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Public Const EWX_LOGOFF = 0
Public Const EWX_SHUTDOWN = 1
Public Const EWX_REBOOT = 2
Public Const EWX_FORCE = 4
Public Const EWX_POWEROFF = 8 ' Yes, I know this one's not in the API Viewer
Then from anywhere, use this:
To shut down:
Call ExitWindowsEx(EWX_FORCE Or EWX_SHUTDOWN, 0)
To reboot:
Call ExitWindowsEx(EWX_FORCE Or EWX_REBOOT, 0)
To log off the current user: (This works for WinNT, the others don't)
Call ExitWindowsEx(EWX_FORCE Or EWX_LOGOFF, 0)
To shut down and turn off the computer: (Only supported under Windows 98 under some motherboards)
Call ExitWindowsEx(EWX_FORCE Or EWX_POWEROFF, 0)
Note: If you use EWX_POWEROFF in a computer that doesn't support auto-turnoff, then it should be the same as EWX_SHUTDOWN.
For WinNT, you can also use
EWX_FORCEIFHUNG = 10
I'm assuming by the name that if the O/S or a process hangs at shutdown, it will be terminated after a timeout period expires...
Thanks for the code and all. But, what I want to do is do a soft reboot....ONLY restart windows, not reboot the computer entirely. You know, when you install some programs, they claim that you need to "restart windows before the changes will take effect," and when you say "OK," it goes to a black screen saying "Windows is restarting..." That's what I want :) Any ideas?
Thanks,
Dave