Board index » delphi » Help: SetSystemTime and AdjustTokenPrivileges

Help: SetSystemTime and AdjustTokenPrivileges

Please email responses to m...@blmnet.com, I'm currently underway and
that is the only way I can get correspondence.
--------------------------------------
Hi all, Hoping someone can help. I'm trying to write a program in
Delphi 5 Pro on Win2k Pro and NT4 sp4 and higher, to update the system
time. I'm on a Navy Ship and we cross timezones quite frequently and
I'm hoping to fix the time problems onboard.

I've got the SETSYSTEMTIME API call working flawlessly when logged in
as administrator but for regular users it fails everytime, and I have
tried the ADJUSTTOKENPRIVILEGES api call but have had exactly 0.00
success rate.

Below is a bit of code that I have tried and I still get the "1314
Required Privilege Not Held" or if I substitute SE_SYSTEMTIME_NAME
instead of the SESYSTEMTIMEPRIVILEGE the LOOKUPPRIVILEGE function
fails with PRIVILEGE NOT FOUND. I have scoured the net looking for
examples and every one looks just like the code below. I'm out of
ideas and almost ready to go to each machine and manually make the
SESYSTEMTIMEPRIVILEGE default to EVERYONE, which will mean that NT has
beaten me and I don't like that idea :-)

Thanks for your help
Brian
m...@blmnet.com

**Since I'm currently in a {*word*104}cafe in PuertoRico and my ship is some
distance away I had to copy this code from a code repository, but it
is identical to my code except for naming conventions.

var
  TokenHandle: THandle;
  NewState, PreviousState: TTokenPrivileges;
  ReturnLength: DWORD;
  SystemTime: TSystemTime;
begin
  if not OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES
or
TOKEN_QUERY, TokenHandle) then
    RaiseLastWin32Error;
  try
    NewState.PrivilegeCount := 1;
// I had tried to change SeSystemTimePrivilege to SE_SYSTEMTIME_NAME
// But it gives a unknown or privilege not found
    if not LookupPrivilegeValue(nil, 'SeSystemtimePrivilege',
    NewState.Privileges[0].LUID) then
      RaiseLastWin32Error;
    NewState.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
    ReturnLength := SizeOf(PreviousState);
    if not AdjustTokenPrivileges(TokenHandle, False, NewState,
SizeOf(NewState), PreviousState, ReturnLength) then
      RaiseLastWin32Error;

    DateTimeToSystemTime( D , SystemTime);

    if not SetSystemTime(SystemTime) then
      RaiseLastWin32Error;

    if not AdjustTokenPrivileges(TokenHandle, False, PreviousState,
SizeOf(PreviousState), NewState, ReturnLength) then
      RaiseLastWin32Error;
  finally
    CloseHandle(TokenHandle);
  end;
end;

 

Re:Help: SetSystemTime and AdjustTokenPrivileges


"Brian" <m...@blmnet.com> skrev i melding
news:af7fd0aa.0110141004.3903abab@posting.google.com...

Quote
> Please email responses to m...@blmnet.com, I'm currently underway and
> that is the only way I can get correspondence.
> --------------------------------------
> Hi all, Hoping someone can help. I'm trying to write a program in
> Delphi 5 Pro on Win2k Pro and NT4 sp4 and higher, to update the system
> time. I'm on a Navy Ship and we cross timezones quite frequently and
> I'm hoping to fix the time problems onboard.

These days I would prefer if you did not leave your own timezone if you're on
a British or an American Navy ship.

--
Bjoerge Saether
Consultant / Developer
http://www.itte.no
Asker, Norway
bjorge@takethisaway_itte.no (remve the obvious)

Re:Help: SetSystemTime and AdjustTokenPrivileges


JRS:  In article <27my7.2052$wF1.69...@news1.oke.nextra.no>, seen in
news:comp.lang.pascal.delphi.misc, Bj?rge S?ther <REMOVE_bsaether@THIS_o
nline.no> wrote at Sun, 14 Oct 2001 21:59:15 :-

Quote
>"Brian" <m...@blmnet.com> skrev i melding
>news:af7fd0aa.0110141004.3903abab@posting.google.com...
>> Please email responses to m...@blmnet.com, I'm currently underway and
>> that is the only way I can get correspondence.
>> --------------------------------------
>> Hi all, Hoping someone can help. I'm trying to write a program in
>> Delphi 5 Pro on Win2k Pro and NT4 sp4 and higher, to update the system
>> time. I'm on a Navy Ship and we cross timezones quite frequently and
>> I'm hoping to fix the time problems onboard.

>These days I would prefer if you did not leave your own timezone if you're on
>a British or an American Navy ship.

Only an American would omit to specify which Navy was in question.  Many
of them seem not really to believe in the existence of other countries;
it's one cause of resentment.

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 Web <URL: http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
 Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
 Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

Re:Help: SetSystemTime and AdjustTokenPrivileges


Maybe your right, I should have put US or British or Austrailian or
some other country and been more specific. But the intent of my post
wasn't to start a political discussion on the policies regarding where
my commanders send my ship and my post wasn't intended to offend any
other countries by the omission of which navy I am part of. THE SOLE
INTENT of my post was to request help on a programming issue. I simply
added the extra for background info on why I needed to change
timezones frequently. I see now that the friendly help that was to be
had a few years ago in the newsgroups has now unfortunatly been lost
and is now reduced to picking apart a post based on nationalities and
political beliefs. What happened to the newsgroups of old?
I'm Sorry to have used your bandwidth and to have asked for help.
-----

Dr John Stockton <s...@merlyn.demon.co.uk> wrote in message <news:q0j2hmCuzty7Ewzt@merlyn.demon.co.uk>...

Quote
> JRS:  In article <27my7.2052$wF1.69...@news1.oke.nextra.no>, seen in
> news:comp.lang.pascal.delphi.misc, Bj?rge S?ther <REMOVE_bsaether@THIS_o
> nline.no> wrote at Sun, 14 Oct 2001 21:59:15 :-
> >"Brian" <m...@blmnet.com> skrev i melding
> >news:af7fd0aa.0110141004.3903abab@posting.google.com...
> >> Please email responses to m...@blmnet.com, I'm currently underway and
> >> that is the only way I can get correspondence.
> >> --------------------------------------
> >> Hi all, Hoping someone can help. I'm trying to write a program in
> >> Delphi 5 Pro on Win2k Pro and NT4 sp4 and higher, to update the system
> >> time. I'm on a Navy Ship and we cross timezones quite frequently and
> >> I'm hoping to fix the time problems onboard.

> >These days I would prefer if you did not leave your own timezone if you're on
> >a British or an American Navy ship.

> Only an American would omit to specify which Navy was in question.  Many
> of them seem not really to believe in the existence of other countries;
> it's one cause of resentment.

Other Threads