In actual applications, some system settings have been modified and windows must be restarted.
After a software program, you must Disable Windows. During the demonstration, you are prohibited from forcibly disabling windows.
To solve the above problems, I have compiled a program to comprehensively solve the above problems.
- Implementation principle:
1. restart Windows, shut down Windows, and end the current user process by calling
Implemented by the exitwindowsex function. This function has two parameters. The previous parameter is represented by ewx_force.
Forcibly shut down Windows without reminding you to save the running results of other applications. The next parameter is ewx_logoff.
Indicates that the current user process is logged out; ewx_shutdown indicates that Windows is disabled; ewx_reboot indicates that
Restart Windows.
2. Disabling windows is disabled. When Windows 98 is disabled, the system sends
The message wm_queryendsession notifies each application to shut down. If the returned message value is 0, it cannot
Disable Windows98.
Figure 1
- Application instance:
- Create a form containing the following controls:
Control name Caption
Form form1 restarts windows
Check box checkbox1 to force end the current user process
Check box checkbox2 Force Shutdown
Check box checkbox3 force restart the machine
Check box checkbox4 disable Shutdown
Check box checkbox5 exit
2. program list:
Unit clsw;
Interface
Uses
Windows, messages, sysutils, classes, graphics, controls, forms, dialogs,
Stdctrls;
Type
Tform1 = Class (tform)
Checkbox1: tcheckbox;
Checkbox2: tcheckbox;
Checkbox3: tcheckbox;
Checkbox4: tcheckbox;
Checkbox5: tcheckbox;
Procedure checkbox1click (Sender: tobject );
Procedure checkbox2click (Sender: tobject );
Procedure checkbox3click (Sender: tobject );
Procedure checkbox5click (Sender: tobject );
Private
Procedure wmqueryendsession (var msg: tmessage );
Message wm_queryendsession;
{Private Declarations}
Public
{Public declarations}
End;
VaR
Form1: tform1;
Implementation
{$ R *. DFM}
Procedure tform1.checkbox1click (Sender: tobject );
VaR ewx_logoff, ewx_force: integer;
Begin
Ewx_logoff: = 0;
Ewx_force: = 4;
Exitwindowsex (ewx_force or ewx_logoff, 0 );
End;
Procedure tform1.checkbox2click (Sender: tobject );
VaR ewx_shutdown, ewx_force: integer;
Begin
Ewx_shutdown: = 1;
Ewx_force: = 4;
Exitwindowsex (ewx_force or ewx_shutdown, 0 );
End;
Procedure tform1.checkbox3click (Sender: tobject );
VaR ewx_reboot, ewx_force: integer;
Begin
Ewx_reboot: = 2;
Ewx_force: = 4;
Exitwindowsex (ewx_force or ewx_reboot, 0 );
End;
Procedure tform1.wmqueryendsession (var msg: tmessage );
Begin
If checkbox4.checked then
MSG. Result: = 1
Else
MSG. Result: = 0;
End;
Procedure tform1.checkbox5click (Sender: tobject );
Begin
Close;
End;
End.
The above programs run in Windows 98 and dephi 4.0.