Solved

system data and time

Posted on 2002-07-01
5
198 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

15 Experts available now in Live!

Get 1:1 Help Now