怎样才能强行关机?这个问题问过好多次还没有理想的答案!(100分)

  • 主题发起人 主题发起人 gxetdc
  • 开始时间 开始时间
G

gxetdc

Unregistered / Unconfirmed
GUEST, unregistred user!
在win98比如进EXCEL 、WORD编辑不提示保存就可关机
用ExitWindowsEx()好旬都有提示的,不知哪位能行,

 
我想用BOOL ExitWindowsEx(UINT uFlags, DWORD dwReserved)函数可以做到你的要求,
主要是用好第一个参数,以下是他们的取值范围:
Value Meaning
EWX_FORCE Forces processes to terminate. When this flag is set, Windows does not send the messages WM_QUERYENDSESSION and WM_ENDSESSION to the applications currently running in the system. This can cause the applications to lose data. Therefore, you should only use this flag in an emergency.
EWX_LOGOFF Shuts down all processes running in the security context of the process that called the ExitWindowsEx function. Then it logs the user off.
EWX_POWEROFF Shuts down the system and turns off the power. The system must support the power-off feature.Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section. Windows 95: Security privileges are not supported or required.
EWX_REBOOT Shuts down the system and then restarts the system. Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section. Windows 95: Security privileges are not supported or required.
EWX_SHUTDOWN Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped. Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section. Windows 95: Security privileges are not supported or required.
这样,EWX_FORCE肯定要的,你要关机的话,EWX_POWEROFF也要,你可试一下这句:
ExitWindowsEx(EWX_FORCE + EWX_POWEROFF, 0);
 
function SetPrivilege(PrivilegeName: String; Enable:Boolean): Boolean;
//PrivilegeName指想要获得权限的常量,
// 如果想要取得其它相应的权限只需要输入相应的常量。
//关闭系统的常量是SeShutdownPrivilege,
//该常量在Delphi中没有声明。
var
NewState,
PreviousState : TTokenPrivileges;
token : THandle;
dwRetLen : DWord;
begin
Result := False;
OpenProcessToken(GetCurrentProcess,
TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, token);
NewState.PrivilegeCount := 1;
if LookupPrivilegeValue(nil, PChar(PrivilegeName),
NewState.Privileges[0].LUID) then
begin
if Enable then
NewState.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED
else
NewState.Privileges[0].Attributes := 0;
dwRetLen := 0;
Result := AdjustTokenPrivileges(token,
False, NewState, SizeOf(PreviousState),
PreviousState, dwRetLen);
end;
CloseHandle(token);
end;

function GetWinVer:Byte;
var OS:TOSVersionInfo;
begin
OS.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
GetVersionEx(OS);
case OS.dwPlatformId of
VER_PLATFORM_WIN32s : Result:=0; //Windows 3.1x/32s
VER_PLATFORM_WIN32_WINDOWS : Result:=1; //Windows 95
VER_PLATFORM_WIN32_NT : Result:=2; //Windows NT
end;
end;

function ShutDownComputer:Boolean;
begin
if GetWinVer=2 then
begin //如果当前系统是Windows NT
SetPrivilege('SeShutdownPrivilege', True);
if not ExitWindowsEx(8, 0) then
SetPrivilege('SeShutdownPrivilege', False);
end
else
ExitWindowsEx(8,0);
end;
 
TO以上两位,
已经试过,
ExitWindowsEx(EWX_FORCE AND EWX_POWEROFF, 0);
ExitWindowsEx(8, 0);
试了WIN98里只是出现登录画面,然后就是重新进入WIN98,
没有关机
 
再加个EWX_SHUTDOWN试试吧!
 
我都试过了,看来是不能给分了
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部