Solved

system data and time

Posted on 2002-07-01
5
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…

738 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