How could I reset my machine using C++ code?

I need to reset a machine (local or remote) from my application (MFC exe). How could I do it?

Thanks.
svillalbaAsked:
Who is Participating?
 
jkrCommented:
"Remote" works only for NT/W2k using "InitiateSystemShutdown()": http://www.mvps.org/win32/processes/rb.c

If you need to restart a Win9x/ME machine, 'ExitWindowsEx()' will work for you:

ExitWindowsEx(EWX_REBOOT, 0);
0
 
ZoppoCommented:
Hi svillalba,

you can either use ExitWindowsEx() or InitiateSystemShutdown() which is not available in Win9x/Me...

hope that helps,

ZOPPO
0
 
CriusCommented:
Wait... Are you sure you want to reset it?
To reset a machine, you can use a simple assembly command, and just tell it to jump (jmp) to memory F0F0:F0F0, and that's a pretty effective reset, though you'll likely lose all your windows unsaved data since it's not a clean shutdown. I believe F0F0:F0F0 is equivalent to FFFF:0000 but I'm not certain.

Here is a list of non-reset alternatives I suggest:

DOS ECHO G=FFFF:0000 ¦ DEBUG  Reboot (warm boot, sometimes cold boot)(2)
Win31* ECHO G=FFFF:0000 ¦ DEBUG  Popup Task Manager, sometimes reboot
Win9* RUNDLL USER.EXE,ExitWindows  Shutdown (3)
Win9* RUNDLL USER.EXE,ExitWindowsExec  Win95: various results, usualy fast shutdown (and lock PC), sometimes restart Windows, sometimes reboot.
Win98: Restart Windows, sometimes reboot.
Win9* RUNDLL SHELL.DLL,RestartDialog  "System Settings Change, Do you want to restart your computer now?" dialog
Win98/ME RUNDLL32 SHELL32.DLL,SHExitWindowsEx n  Where n can be any combination (sum) of the following numbers: (4)
0    Logoff
1    Shutdown
2    Reboot
4    Force
8    Poweroff (if supported by the hardware)
 
Win98/ME RUNONCE.EXE -q  Reboot (4)
NT See Reboot NT on my Solutions found in alt.msdos.batch page Reboot immediately
NT RUNDLL32 USER32.DLL,ExitWindowsEx
RUNDLL32 USER32.DLL,ExitWindowsEx  Logoff (most systems require the command to be called twice before logging off)
NT+RK SHUTDOWN /L /R /T:0 /Y  Immediate shutdown & reboot
NT+RK SHUTDOWN /L /T:10 /Y /C  Shutdown in 10 seconds, close without saving (can be stopped during those 10 seconds using SHUTDOWN /A)
XP SHUTDOWN -r -t 10  Reboot after a 10 seconds delay (can be stopped during those 10 seconds using SHUTDOWN -a)
XP SHUTDOWN -s -t 01  Shutdown after a 1 second delay (but no poweroff)
Kix $RC = SHUTDOWN( "\\server", "Shutting down...", 10, 1, 0 )  Shutdown in 10 seconds, with message, close without saving, no reboot
Kix $RC = SHUTDOWN( "\\server", "", 0, 1, 1 )  Immediate shutdown & reboot, without a message
Kix $RC = LOGOFF( 1 )  Logoff, forcing applications to close (use 0 instead of 1 if you don't want to force applications to close)
WSH [1] Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")
[2]
[3] for each OpSys in OpSysSet
[4]     OpSys.Reboot()
[5] next  Reboot
 
(Remove [line numbers].
Found in a forum posting by Alex Angelopoulos on www.developersdex.com)
OS/2 START /PM SHUTDOWN && EXIT  Shutdown (5)
OS/2 SETBOOT /IBD:C:  Unconditional shutdown & reboot
OS/2 SETBOOT /IBA:nonsense  Unconditional shutdown & failing reboot (6)
OS/2 LOGOFF  Logoff (both LAN Server client and Peer)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.