Solved

Set System Time NT

Posted on 1998-04-23
4
218 Views
Last Modified: 2010-04-06
Does someone have an easy reliable way of setting system time in NT and Win95 including AdjustTokenPrivileges in NT.  I'm just not getting it.

Thanks
0
Comment
Question by:rcastle
[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
  • 3
4 Comments
 
LVL 1

Expert Comment

by:Greedy
ID: 1336693
Yeah I saw it...now to find it...the artile tile had time, nt and ID in it...found a 95 one...I'll keep looking for the NT one...

Setting time system with Delphi
abeldup@unison.co.za (Abel du Plessis)

"Vitor Martins" <nop47019@mail.telecom.pt wrote:


How can I set the clock system time and date in a program  with Delphi 2.0
in Win 95
This works for us:


--------------------------------------------------------------------------------

//******************************************************************************
//Public function SetPCSystemTime changes the system date and time.
//Parameter(s): tDati  The new date and time
//Returns:      True if successful
//              False if not
//******************************************************************************
function SetPCSystemTime(tDati: TDateTime): Boolean;
var
   tSetDati: TDateTime;
   vDatiBias: Variant;
   tTZI: TTimeZoneInformation;
   tST: TSystemTime;
begin
   GetTimeZoneInformation(tTZI);
   vDatiBias := tTZI.Bias / 1440;
   tSetDati := tDati + vDatiBias;
   with tST do
   begin
        wYear := StrToInt(FormatDateTime('yyyy', tSetDati));
        wMonth := StrToInt(FormatDateTime('mm', tSetDati));
        wDay := StrToInt(FormatDateTime('dd', tSetDati));
        wHour := StrToInt(FormatDateTime('hh', tSetDati));
        wMinute := StrToInt(FormatDateTime('nn', tSetDati));
        wSecond := StrToInt(FormatDateTime('ss', tSetDati));
        wMilliseconds := 0;
   end;
   SetPCSystemTime := SetSystemTime(tST);
end;

--------------------------------------------------------------------------------

0
 
LVL 1

Accepted Solution

by:
Greedy earned 200 total points
ID: 1336694
taken from http://www.chami.com/tips/delphi/120496D.html

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
 
LVL 6

Author Comment

by:rcastle
ID: 1336695
Thanks Greedy, doubling points for complete answer pointing out my stupidity and pointing me back at chami which I should have checked.
0
 
LVL 1

Expert Comment

by:Greedy
ID: 1336696
No prob man...thanks
0

Featured Post

Technology Partners: 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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 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