Solved

system data and time

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

705 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