Solved

system data and time

Posted on 2002-07-01
5
199 Views
Last Modified: 2012-05-04
Hi,

I had my privilege to change the computer's system time and date disabled.  How can I enable this privilege progammatically?  I tried to use AdjustTokenPrivileges
but it doesn't seem to work.

Thanks!

0
Comment
Question by:jjchua
5 Comments
 
LVL 7

Expert Comment

by:Cynna
ID: 7124058
jjchua,

> I had my privilege to change the computer's system time and date disabled.How can I enable this privilege progammatically?

You can't do this if admin disabled you to use those privileges.



> I tried to use AdjustTokenPrivileges...

AdjustTokenPrivileges enables the SE SYSTEMTIME NAME privilege (that allows the time to be set) for the calling process. It "activates" your sys time privilege, provided you have one to start with (which you don't).
0
 

Author Comment

by:jjchua
ID: 7125680
Hi Cynna,

Thanks for replying to my email.  Is there a way to add this privilege programmatically?  
0
 
LVL 7

Accepted Solution

by:
Cynna earned 50 total points
ID: 7126786
Try this for WinNT (from chami):

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
0
 

Expert Comment

by:CleanupPing
ID: 9343125
jjchua:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 9459926
jjchua,
No comment has been added lately (18 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to Cynna http:#7126786

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

anAKiN
EE Cleanup Volunteer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Communication Between RC4 Delphi <-> PHP 3 101
Delphi 2 51
Tviruailstringtree sort multi columns on header click 1 54
tvirtualstringtree freeze when load too manny images 10 53
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now