procedure Shutdown; var hToken:THANDLE; tkp:TOKEN_PRIVILEGES; ReturnLength,BufferLength: DWORD; ver:TOSVersionInfo; begin ver.dwOSVersionInfoSize:=sizeof(TOSVersionInfo); if not GetVersionEX(ver) then Exit; if ver.dwPlatformId<VER_PLATFORM_WIN32_NT then begin ExitWindowsEx(EWX_POWEROFF or EWX_FORCE, 0); exit; end; // Get a token for this process. if not OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES OR TOKEN_QUERY, hToken) then begin ShowMessage('OpenProcessToken'); Exit; end; // Get the LUID for the shutdown privilege. // SE_SHUTDOWN_NAME :="SeShutdownPrivilege"; // Dest:=@Buf[1]; LookupPrivilegeValue(nil,'SeShutdownPrivilege' , tkp.Privileges[0].Luid); tkp.PrivilegeCount := 1; // one privilege to set tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;// Get the shutdown privilege for this process. BufferLength:=0; ReturnLength:=0; AdjustTokenPrivileges(hToken, LongBool(false), tkp, BufferLength,nil, ReturnLength);// Cannot test the return value of AdjustTokenPrivileges. if GetLastError() <> ERROR_SUCCESS then begin ShowMessage('AdjustTokenPrivileges'); Exit; end; // Shut down the system and force all applications to close. if not ExitWindowsEx(EWX_POWEROFF or EWX_FORCE, 0) then begin ShowMessage('ExitWindowsEx'); Exit; end; end;
var
hToken:THANDLE;
tkp:TOKEN_PRIVILEGES;
ReturnLength,BufferLength: DWORD;
ver:TOSVersionInfo;
begin
ver.dwOSVersionInfoSize:=sizeof(TOSVersionInfo);
if not GetVersionEX(ver) then Exit; if ver.dwPlatformId<VER_PLATFORM_WIN32_NT then
begin
ExitWindowsEx(EWX_POWEROFF or EWX_FORCE, 0);
exit;
end; // Get a token for this process.
if not OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES OR TOKEN_QUERY, hToken) then
begin
ShowMessage('OpenProcessToken');
Exit;
end;
// Get the LUID for the shutdown privilege.
// SE_SHUTDOWN_NAME :="SeShutdownPrivilege";
// Dest:=@Buf[1]; LookupPrivilegeValue(nil,'SeShutdownPrivilege' , tkp.Privileges[0].Luid); tkp.PrivilegeCount := 1; // one privilege to set
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;// Get the shutdown privilege for this process.
BufferLength:=0;
ReturnLength:=0;
AdjustTokenPrivileges(hToken, LongBool(false), tkp, BufferLength,nil, ReturnLength);// Cannot test the return value of AdjustTokenPrivileges. if GetLastError() <> ERROR_SUCCESS then
begin
ShowMessage('AdjustTokenPrivileges');
Exit;
end;
// Shut down the system and force all applications to close. if not ExitWindowsEx(EWX_POWEROFF or EWX_FORCE, 0) then
begin
ShowMessage('ExitWindowsEx');
Exit;
end;
end;
2,我这里有个很好的API文档,每个API都有DELPHI的例子,如果你要,请尽快联系我:)
你好,请寄到我.mo,重谢你
我hotmail邮箱打开很慢
我给你发消息了
我上不了QQ,只有一个这个域信箱,没办法,
我还是没有收到,可以再给我发一次吗?[email protected],谢谢你
文档已收到,谢谢你.请接分
根据规则,最多只能给79分,谢谢你