SetSystemTime: why won't this work???
I am trying to change the system time in my program. I've figured out
that I need to enable the access token to do this, and I used this
example code that someone posted to do that. For some reason this
does not work all the time, because when I call SetSystemTime() it
returns a false value. Can anyone tell me why this code doesn't work?
Any help would be appreciated.
procedure TForm1.SetPrivilege(sPrivilegeName : string; bEnabled :
boolean );
var
TPPrev,TP : TTokenPrivileges;
Token : THandle;
dwRetLen : DWord;
result : boolean;
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 else
begin
TP.Privileges[ 0 ].Attributes := 0;
end;
dwRetLen := 0;
AdjustTokenPrivileges(Token,False,TP,SizeOf( TPPrev
),TPPrev,dwRetLen );
end;
CloseHandle( Token );
end;
to enable the systemtime privilege i just use:
SetPrivilege('SeSystemtimePrivilege',True);