找了一段c的程序,可老是转不过来,有变量类型错误,能否给我一个在delphi下能直接调的函数?谢谢。
c的程序如下:
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
MessageBox("err OpenProcessToken");// Get the LUID for the shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &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.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES)NULL, 0);// Cannot test the return value of AdjustTokenPrivileges.
if (GetLastError() != ERROR_SUCCESS)
MessageBox("err AdjustTokenPrivileges");// Shut down the system and force all applications to close.
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
MessageBox("err ExitWindowsEx");
c的程序如下:
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
MessageBox("err OpenProcessToken");// Get the LUID for the shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &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.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES)NULL, 0);// Cannot test the return value of AdjustTokenPrivileges.
if (GetLastError() != ERROR_SUCCESS)
MessageBox("err AdjustTokenPrivileges");// Shut down the system and force all applications to close.
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
MessageBox("err ExitWindowsEx");
var
hToken: THANDLE;
hProc: THANDLE;
mLUID: TLargeInteger;
mPriv, mNewPriv: TOKEN_PRIVILEGES;
mBufferLength: DWord;
begin
Result:=false;
if not (M_1Reboot_2Power in [1, 2]) then exit;
hProc := GetCurrentProcess();
OpenProcessToken(hProc, TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY, hToken);
LookupPrivilegeValue('', 'SeShutdownPrivilege', mLUID);
mPriv.PrivilegeCount := 1;
mPriv.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
mPriv.Privileges[0].Luid := mLUID;
AdjustTokenPrivileges(hToken, False, mPriv, (4 + (12 * mPriv.PrivilegeCount)), mNewPriv, mBufferLength);
GetLastError;
case M_1Reboot_2Power of
1: Result := ExitWindowsEx(EWX_FORCE+EWX_REBOOT,0);
2: Result := ExitWindowsEx(EWX_FORCE+EWX_POWEROFF, 0);
end;
end;