当前位置:主页>仓库管理软件> 列表

定时关机问题,在线等.....急 找速达软件

仓库管理软件版1楼: 谁知道,怎么用DELPHI 实现定时关机啊windows.exitwindowscs(0,0)好象是重起,把参数该成什么就是关机了啊,我试了几个都是重起.

2楼: http://pd.szhqzx.net/zlc/Article%5Cdelphiuseapiexp.htm 如速达软件

3楼: procedure TCloseAllAppAndShutDown.run;
var
hdlProcessHandle : Cardinal;
hdlTokenHandle : Cardinal;
tmpLuid : Int64;
tkpPrivilegeCount : Int64;
tkp : TOKEN_PRIVILEGES;
tkpNewButIgnored : TOKEN_PRIVILEGES;
lBufferNeeded : Cardinal;
Privilege : array[0..0] of _LUID_AND_ATTRIBUTES;
begin
//关闭计算机
hdlProcessHandle := GetCurrentProcess;
OpenProcessToken(hdlProcessHandle,
(TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY),
hdlTokenHandle);

// Get the LUID for shutdown privilege.
LookupPrivilegeValue('''', ''SeShutdownPrivilege'', tmpLuid);
Privilege[0].Luid := tmpLuid;


Privilege[0].Attributes := SE_PRIVILEGE_ENABLED;
tkp.PrivilegeCount := 1; // One privilege to set
tkp.Privileges[0] := Privilege[0];
// Enable the shutdown privilege in the access token of this
// process.
AdjustTokenPrivileges(hdlTokenHandle,
False,
tkp,
Sizeof(tkpNewButIgnored),
tkpNewButIgnored,
lBufferNeeded);

if ExitWindowsEx((EWX_SHUTDOWN Or EWX_FORCE Or EWX_REBOOT), $FFFF) then
Raise Exception.create(''ExitWindowsEx failed with code ''
+ inttostr(GetLastError));;
end;

4楼: 以下的两个函数,执行WinExitInNT(EWX_SHUTDOWN+EWX_FORCE+EWX_POWEROFF)

function SetPrivilege(sPrivilegeName: string;
bEnabled: Boolean): Boolean;
var
TPPrev,TP:TTokenPrivileges;
Token:THandle;
dwRetLen:DWord;
begin
Result:=False;


OpenProcessToken(
GetCurrentProcess,
TOKEN_ADJUST_PRIVILEGES
or TOKEN_QUERY,
Token);
TP.PrivilegeCount:=1;
if (LookupPrivilegeValue(
Nil,
Pchar(sPrivilegeName),
TP.Privileges[0].LUID)
) then
begin
if (bEnabled) then
begin
TP.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;
end;
end else
begin
TP.Privileges[0].Attributes:=0;
end;
dwRetLen:=0;
Result:=AdjustTokenPrivileges(
Token,
False,
TP,
SizeOf(TPPrev),
TPPrev,
dwRetLen
);
CloseHandle(Token);
end;

function WinExitInNT(iFlags: integer): boolean;
begin
Result:=True;
//SE_SHUTDONW_NAME的权限值是SEShutdownPrivilege
if (SetPrivilege(''SeShutdownPrivilege'',True)) then
begin
if (not ExitWindowsEx(iFlags,0)) then
Result:=False;
SetPrivilege(''SeShutdownPrivilege'',False);
end
else begin


Result:=False;//句柄错误
end;
end;

5楼: 帮顶!

╭=========================================╮

80G海量源代码,控件,书籍全免费狂下不停!

http://www.source520.com

╰=========================================╯

6楼: 多人接受答案了。