AzzerShaw
(Seasoned Scripter)
2003-11-07 01:58 PM
Shelling Net Time

Hi guys & galls

I know i should be using W32TIME [Wink] BUT we are in the middle of a migration and I havent got time to push it out (especially when we will have it when we move to 2003)

But i am having problems at the moment with setting the time.
I have changed the permissions for changing the time using NTRIGHTS.exe but am having a problem with shelling net time. I know I can put this in my login script but was wondering if it was possible to set the time at the same time as the permissions change?
I have whipped up this little number below using a script I found on this site (sorry to the author but I cannot remember you name!!)

code:
  
Break on


Open (1,"\\MYPC\copy\aaron.txt")

Do
$compname = ReadLine(1)

Shell "%COMSPEC% /c ntrights.exe +r SeSystemtimePrivilege -u Everyone -m $compname"

Shell "cmd /c net time \\server /set /y"


Until $compname = ""

I have tried using settime but this also doesnt work? HELP !!!!

Also is it possible to revert the permissions after the time has been set?

[ 07. November 2003, 14:06: Message edited by: AzzerShaw ]


Kdyer
(KiX Supporter)
2003-11-07 02:52 PM
Re: Shelling Net Time

Doesn't the KiXtart native command SETTIME work?

Kent


Les
(KiX Master)
2003-11-07 03:17 PM
Re: Shelling Net Time

quote:
I havent got time to push it out
Unless you are talking about NT4 clients, W32Tm.exe is already running as a service. The effort required to "push it out" as you say, is the same as your proposed hack. THe only problem with your hack is that if users manually change the time, it will most assuredly break your kerberos authentication!


AzzerShaw
(Seasoned Scripter)
2003-11-07 03:18 PM
Re: Shelling Net Time

Nope tried this script and this doesnt work either, should the changes happen straight away?

code:
  
Break on


Open (1,"\\mypc\copy\aaron.txt")

Do
$compname = ReadLine(1)

Shell "%COMSPEC% /c ntrights.exe +r SeSystemtimePrivilege -u Everyone -m $compname"

SetTime "\\timeserver"

Until $compname = ""



AzzerShaw
(Seasoned Scripter)
2003-11-07 03:22 PM
Re: Shelling Net Time

Hi Les

Yes I am talking about NT 4.0, sorry should of said.

Do you know if it is possible to revert the changes back afterwards ?


ShaneEP
(MM club member)
2003-11-07 04:07 PM
Re: Shelling Net Time

Are you sure the text file is being opened? Maybe you should add some error checking.

AzzerShaw
(Seasoned Scripter)
2003-11-07 04:11 PM
Re: Shelling Net Time

Hello bud

Yes it opens the file fine as it changes the permissions fine, maybe I should try and put a sleep in there. I'll let you knows

Aaron


AzzerShaw
(Seasoned Scripter)
2003-11-07 04:17 PM
Re: Shelling Net Time

nadgers. Didnt work !!

Anyone got suggestions?


AzzerShaw
(Seasoned Scripter)
2003-11-07 04:19 PM
Re: Shelling Net Time

Done some error checking and the value it returns after the settime is "0" ha ha great...

HELP ??


Sealeopard
(KiX Master)
2003-11-07 04:20 PM
Re: Shelling Net Time

Firstof sall, I'd never give the 'Everyone' group the right to change the systemtime. Restrict this right to your actual users, e.g. 'Domain Users'.

You state that SETTIME does not work. What is the error code returned by SETTIME?

I also agree that Win32Time is the way to go. The 'no time to push it out' is a poor excuse as you now spend time trying to hack your way into making SETTIME work.

Finally, it seems you change the rights on a remote computer but then you try to synchronize the time on your local computer?


Kdyer
(KiX Supporter)
2003-11-07 04:23 PM
Re: Shelling Net Time

Cannot "push" out W32Time?

Try this out -
code:
 ;Time installation
:timeserv
IF @dos >=5 ; Don't do the whole process on Windows 2000/XP
SETTIME @ldomain ; Sync the local clock
RETURN
ELSE
IF exist($systemdrive+'\w32update.ok')
RETURN
ELSE
;Has this been setup?
IF KEYEXIST('HKLM\System\CurrentControlSet\Services\W32Time')=0
;Check for Time files
IF 0=EXIST($windir+'\SYSTEM32\w32time.exe')
COPY @ldrive+'Reskit\TimeService\W32Time\company\Secondary\w32time.exe' $windir+'\SYSTEM32'
ENDIF
IF 0=EXIST($windir+'\w32time.ini')
COPY @ldrive+'Reskit\TimeService\W32Time\company\Secondary\w32time.ini' $windir
ENDIF
;Execute the time service to start automatically
RUN $windir+'\SYSTEM32\w32time.exe -automatic'
;Have to add a small pause to start the service
SLEEP 1
;Execute a Net Start to Start the Service
SHELL '%COMSPEC% /C NET START W32TIME > nul'
SLEEP 1
SHELL '%COMSPEC% /C w32time.exe -update > nul'
COPY $drive+'\system32\config.nt' $systemdrive+'\w32update.ok'
;CLS
RETURN
ELSE
;?'Updating Time Service.. One moment please'
SHELL '%COMSPEC% /C net stop w32time > nul'
SLEEP 1
SHELL '%COMSPEC% /C w32time.exe -remove > nul'
SLEEP 1
SHELL '%COMSPEC% /C w32time.exe -automatic > nul'
SLEEP 1
SHELL '%COMSPEC% /C net start w32time > nul'
SLEEP 1
SHELL '%COMSPEC% /C w32time.exe -update > nul'
COPY $windir+'\system32\config.nt' $systemdrive+'\w32update.ok'
RETURN
ENDIF
ENDIF
RETURN
ENDIF

It is some really old code I have lying around and probably needs to be cleaned up.

Kent

[ 07. November 2003, 16:24: Message edited by: kdyer ]


Sealeopard
(KiX Master)
2003-11-07 04:30 PM
Re: Shelling Net Time

A similar deployment script is here: Time Snchronize

AzzerShaw
(Seasoned Scripter)
2003-11-07 04:32 PM
Re: Shelling Net Time

I was waiting for your grilling Jens ha ha [Wink]

yes you are correct I will change to domain users.

The error code as explained above returned as 0.

I said as the top i would rather use w32time but my superior (ha ha) has said that the time service will remain the same. (It has to be tested and go through audit etc etc)

quote:

Finally, it seems you change the rights on a remote computer but then you try to synchronize the time on your local computer?

Exactly my orginall point, is it possible to use either settime or net time so it will adjust the time remotley ?


Sealeopard
(KiX Master)
2003-11-07 04:34 PM
Re: Shelling Net Time

SETTIME and NET TIME both do the same. They synchronize the date/time of the local computer against a remote time server. Not the other way around!

AzzerShaw
(Seasoned Scripter)
2003-11-07 04:40 PM
Re: Shelling Net Time

Pants.

So im stuffed then?

Is there anything else?


Kdyer
(KiX Supporter)
2003-11-07 04:46 PM
Re: Shelling Net Time

Why can't you deploy w32time? That is best and easiest way aroudn this. You can have it re-sync several times a day too (especially with large db files, etc.)

Kent


AzzerShaw
(Seasoned Scripter)
2003-11-07 04:52 PM
Re: Shelling Net Time

Alright you twisted my arm, I'll give it a go in out test pc's.

Just out of interest Kent, how do you run your script because it looks like its being run locally?

Do you schedule a task or sumfin?


Kdyer
(KiX Supporter)
2003-11-07 04:54 PM
Re: Shelling Net Time

Script runs all from the server as the user running it.

Kent

[ 07. November 2003, 16:54: Message edited by: kdyer ]


Sealeopard
(KiX Master)
2003-11-07 04:55 PM
Re: Shelling Net Time

I pushed mine out via scheduled task. However, you can also use an admin script to install it on all computers.

AzzerShaw
(Seasoned Scripter)
2003-11-07 05:05 PM
Re: Shelling Net Time

Thanks Jens, ill try the admin script.

Once last thing though, I have tried to retreive info on from technet

folloing this link TechNet: W32Time Network Time Service for Windows NT 4.0

But I think Bill got something against me and has moved the link and I cant find where it is.

Does anyone have the necceseary files for w32time and some info?