Since hours I try to use AdjustWithTokenPrivileges to grant my own Process
the seSystemTimePrivilege.
I am not able to get the function work. NT always reports an error 998
(Invalid access to memory location).
Since the Delphi 5 - windows.pas seems to have an overload problem with the
AdjustWithTokenPrivileges - Functions, I import the function myself:
function AdjustTokenPrivileges(TokenHandle: THandle; DisableAllPrivileges:
BOOL;
NewState: PTokenPrivileges; BufferLength: DWORD;
PreviousState: PTokenPrivileges; ReturnLength: PDWORD): BOOL; external
advapi32 name 'AdjustTokenPrivileges';
And this is, how I try to use it:
function SetTime(datetime : TDateTime) : Boolean;
var
systime : SYSTEMTIME;
hToken : Thandle;
Priv : TTOKENPRIVILEGES;
Save : TTOKENPRIVILEGES;
size : DWord;
begin
try
... something...
if OpenProcessToken(GetCurrentProcess, (TOKEN_ADJUST_PRIVILEGES or
TOKEN_QUERY), hToken) then
begin
Priv.PrivilegeCount := 1;
if
LookupPrivilegeValue(nil,'SeSystemtimePrivilege',Priv.privileges[0].luid)
then
begin
priv.privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken,false,@Priv,sizeof(save),@save,@size);
<----- error 998
end;
end;
end;
I also tried to set other privileges, but with the same result. It doesn't
seem to have something to do with the Sort of privileges. There is an
general problem in my code, I am not able to find.
I also tried to use this call:
AdjustTokenPrivileges(hToken,false,@Priv,0,nil,nil);
This generates an Error 87: INVALID_Parameter
??? I don'T know why. The API - Documentation says, it is allowed to set
those parameters to NULL.
Im am logged in as admin, so the seSystemTime - Privilege wouldn't even be
needed! I don't think it has to do with some missing user rights.
Can anybody help me please?
Thanks in advance and have a nice day,
Lutz Klein
best regards,
Marcel van Brakel
Project JEDI: http://delphi-jedi.org
Do not send me private e-mail unless explicitly requested otherwise.
If you do anyway please include a billing address...
Lutz Klein