Shut down, restart and logoff?

How to shut down, restart and logoff a computer?
The codes should be able to FORCE all programs to close WITHOUT user's interventions, eg. ask the user to save, confirm exit, etc.
In addition, please tell me if the codes provided are compatible with NT.
Thanks.
yingkitAsked:
Who is Participating?
 
Grayl1Connect With a Mentor Commented:
Hi!

Use “ExitWindowsEx(EWX_FORCE + EWX_SHUTDOWN, 0);” or “ExitWindowsEx(EWX_FORCE + EWX_REBOOT, 0);” or “ExitWindowsEx(EWX_FORCE + EWX_LOGOFF, 0);” to force ALL apps to close and then shutdown/reboot/logoff your computer. Nothing can stop it. It is so powerful that if you use Active Desktop in Win 98 as “view as webpage” then you will have to click the “Restore Active Desktop” link on your desktop next time you start your computer.

Good luck!
0
 
MotazCommented:
Use ExitWindowsEx

see the help for more information about parameters which enables you to :

Enforce shutdown
Reboot
Logoff
and to see the difference between Windows versions

Motaz
0
 
yingkitAuthor Commented:
I have tried:
ExitWindowsEx(EWX_FORCE and EWX_SHUTDOWN,0);
ExitWindowsEx(EWX_FORCE and EWX_LOGOFF,0);
ExitWindowsEx(EWX_FORCE and EWX_REBOOT,0);
However, they cannot force all programs to close, eg. an unsaved text file in Notepad, it asks me to confirm saving.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
MotazCommented:
When you click cancel save, did the computer resume to shutdown or it stopped shutdown?
0
 
yingkitAuthor Commented:
It stopped shutdown and Notepad remained here.
0
 
MaximWCommented:
In order to reboot the system in Win NT you need to adjust the process privileges before calling ExitWindowsEx
0
 
niknoxeCommented:
Hi,

I'm struggling with this under NT, is is not working correct under NT. You use it with 98?

You must have the correct rights to shutdown a program (at least under NT). In the KB there is one example on how to impersonate..

If you need more, tell me.

CU
0
 
MaximWCommented:
I used it with Win NT(workst,serv),2000
it works. Would you like a sample?
0
 
yingkitAuthor Commented:
This question has a deletion request Pending
0
 
niknoxeCommented:
This question no longer is pending deletion
0
 
niknoxeCommented:
Yes, please niknoxe@hotmail.com
0
All Courses

From novice to tech pro — start learning today.