Rebooting from an application

I need to have my application reboot the system if a certain event occures.  

What is the command to reboot from C++?  I am using Win3.1 !  

(Sorry, this app needs to run on a 4 meg machine and for this and other reasons, we are using Windows 3.1 and therefore the MSVC++ 1.52 compiler)
azarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lif081199Commented:
Here is an article from the MSDN. Very easy to convert it into a short inline assembly function :

How to Reboot Your Machine Within a MASM Application
Article ID: Q68805

The information in this article applies to:
Microsoft Macro Assembler for MS-DOS, version 5.0, 5.1, 5.1a, 6.0, 6.0a, and 6.0b


SUMMARY
You can perform a complete reboot (cold boot) on an 8086-based machine by jumping to the address FFFF:0000. This action also reboots many 80286 and 80386 machines. The address contains a jump instruction that leads to the machine's initialization code. For this method to succeed, your machine must be in real-mode operation.



MORE INFORMATION
To prevent a memory check on IBM and many compatibles (warm boot), you should store the value 0 x 1234 in the memory location at 0040:0072. On 100-percent IBM BIOS compatible machines, an alternative method is to call int 19h instead of jumping to the address mentioned above.



Sample Code
; Assemble options needed: none

..MODEL small

..CODE

Start:

    mov ax, @data                 ; Load ds with data segment
    mov ds, ax

    mov ax, 40h                   ; These three lines cause a memory
    mov es, ax                    ; test NOT to be performed. To
    mov WORD PTR es:[72h], 1234h  ; do a memory test, remove them.

    jmp DWORD PTR b_vec           ; Jump to the reboot address


..DATA
b_vec   DW 00000h                 ; Offset of reboot vector
        DW 0FFFFh                 ; Segment of reboot vector


..STACK
END Start
0
basantCommented:
Before using the Hardcore
rebooting. you can try this.


What you can do is :

Step 1 : Find the Handle of
Program Manager.

hWnd = FindWindow("Progman", ..);
// Check for Argument.

Step 2 :
Post a Shutdown Message to
this Window ( WM_CLOSE)

PostMessage( hWnd,WM_CLOSE, .. );

Step 3 :
Find the Handle of the Window which
asks for Confirmation.
say it is hWnd2

Step 4 :
Give the confirmation.

This will put your windows to
close and Dos Prompt will
come.

After that You can startup any
DOS program which reboot the system.
0
nietodCommented:
Why not just use ExitWindows()?
0
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Shay050799Commented:
try PostMessage(WM_CLOSE,HWND_BROADCAST)
0
basantCommented:
Yes I agree to nietod.
I forgot the Call ExitWindows()
0
lif081199Commented:
Me too :)
I forgot ExitWindows()
Thanks Nietod !!!
0
nietodCommented:
Well, is there a reason why ExitWindows() can't be used?  Azar?  Otherwise it seems like a good answer.
0
lif081199Commented:
Of course !
0
rgoughCommented:
Is ExitWindows() supported in Windows 3.1?  MSDN October 1999 lists the requirements of ExitWindows() to be Windows 95 or later or Windows NT 3.51 or later.  I don't have a 3.1 machine to test it out on and have done very little 3.1 programming so I can't say for sure that it won't work.
0
nietodCommented:
The new windows docs never mention windows 3.x   ExitWindows() was available.
0
mflamCommented:
MSDN: ExitWindows() requires Win95 or later... I don't have the 16 bit installed anymore.
Try it out and tell us!

I know that we used a freeware dos utility called "Shutdown.exe" from the web that did a REAL shutdown. Because calling from the windows only asked politely if we could do it.
It found window after window, forced it down, and finally closed Windows itself.

Moshe
0
mflamCommented:
Nietod is right.
This is from Microsoft about the difference between win3.1 and win3.11:

....etc. etc...
In addition, the following 5 files were changed:


KRNL386.EXE: Minimal kernel changes to more gracefully shut down the Windows system after installing products which call the ExitWindows API to shut Windows down before returning focus to program manager.

....etc. etc...

Good luck!
(BTW I think it only opens the "Do you want to shut down windows" dialog.
You will have to use the FindWindow and "Press" the OK.)

Moshe
0
luisrCommented:
Try

ExitWindows(EW_EXITWINDOWS, 0);

or something like that (or simply pass 0 as both parameters). I don't remember exactly. And it DOES exist in Windows 3.0 and later (EW_RESTARTWINDOWS and EW_REBOOTSYSTEM only work in Windows 3.1 and later).
0
luisrCommented:
From the Windows 3.1 WINDOWS.H:

BOOL    WINAPI ExitWindows(DWORD dwReturnCode, UINT wReserved);

#define EW_RESTARTWINDOWS 0x42
#if (WINVER >= 0x030a)
#define EW_REBOOTSYSTEM   0x43

BOOL    WINAPI ExitWindowsExec(LPCSTR, LPCSTR);
#endif  /* WINVER >= 0x030a */



Here we can see that the Restart flag works in Windows 3.0 (it was undocumented) and the Reboot flag only in 3.1 and later.

0
sun307Commented:
Why don't you try InitaiateSystemShutdown API function. It gives you the flexibility of even rebooting the machine.
0
nietodCommented:
aar, are you out there?

sun307, that is almost certainly not available on 3.11.
0
azarAuthor Commented:
Thanks everybody
I spaced on the ExitWindows command - I'm sure it works using the REBOOYSYSTEM flag

nietod - please send it as an 'answer' and I'll get you the points

0
nietodCommented:
thanks.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.