Solved

Set System Time NT

Posted on 1998-04-23
4
214 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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10, DigitalPersona Fingerprint reader and MySQL 6 336
Delphi XE10, MySQL Query 4 167
Delphi Form ownership 4 114
How to convert memory stream to PDF file 6 120
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…

830 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