Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Error 998 with AdjustTokenPrivileges

158 views
Skip to first unread message

Lutz Klein

unread,
Jul 3, 2001, 7:37:36 PM7/3/01
to
Hi folks!

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

Marcel van Brakel

unread,
Jul 4, 2001, 1:02:04 AM7/4/01
to
In article <3b4259b4$1_1@dnews>, Devel...@Konzept-plus.de says...

> function AdjustTokenPrivileges(TokenHandle: THandle; DisableAllPrivileges:
> BOOL;
> NewState: PTokenPrivileges; BufferLength: DWORD;
> PreviousState: PTokenPrivileges; ReturnLength: PDWORD): BOOL; external
> advapi32 name 'AdjustTokenPrivileges';

You seem to be missing a 'stdcall' here. Other then that I don't see
anything wrong with the code though those 7 letters are sufficient to
prevent it from ever working. If it still doesn't work after you add it
maybe you can have a look at the JclSecurity unit from the JEDI Code
Library (http://delphi-jedi.org) which has wrapper functions for this
purpose (as easy as EnableProcessPrivilege(SE_DEBUG_NAME)).

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

unread,
Jul 4, 2001, 12:41:52 PM7/4/01
to
Thanks Marcel, I'm ashamed! That solved the problem! That solved the problem
with the "wrong parameter" also. How could I be so blind on both eyes :o) ?

Lutz Klein

0 new messages