Go Back   Wiki NewForum | Latest Entertainment News > Career Forum & Tips > Tech Forum & Tutorial > Oracle Database, SQL, Application, Programming


Show your ID before changing the system time


Reply
Views: 1894  
Thread Tools Rate Thread
  #1  
Old 08-20-2010, 11:10 AM
bholas bholas is offline
Award Winner
 
Join Date: Apr 2010
Posts: 4,977
Default Show your ID before changing the system time

Changing the system time using the Win32 API isn't as easy as it was in the Win16 world. This is because in Windows NT environment you have to get certain security permissions before changing the system time. Here's how to put the Windows security guard to sleep and change the time:
function SetPrivilege(
sPrivilegeName : string;
bEnabled : boolean )
: boolean;
var
TPPrev,
TP : TTokenPrivileges;
Token : THandle;
dwRetLen : DWord;
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;
Result := AdjustTokenPrivileges(
Token,
False,
TP,
SizeOf( TPPrev ),
TPPrev,
dwRetLen );
end;

CloseHandle( Token );
end;

procedure ChangeSystemTime;
var
st : TSystemTime;
begin
if( SetPrivilege(
'SeSystemtimePrivilege',
True ) )then
begin
GetLocalTime( st );

//
// change time using st structure
// for example, to 10:30pm
//
st.wHour := 22;
st.wMinute := 30;

SetLocalTime( st );
// or :
// SetSystemTime( st );

SetPrivilege(
'SeSystemtimePrivilege',
False );
end;
end;

Reply With Quote
Reply

Tags
programming tips

New topics in Oracle Database, SQL, Application, Programming





Powered by vBulletin® Version 3.8.10
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
WikiNewForum)