Solved

BatchFile: Simultanious execution

Posted on 2012-03-12
4
248 Views
Last Modified: 2012-06-27
Hi there,

I just did this batch file that will simultaniously SET the time on the network computers.

If I remove the ping delay line, it is faster, but I get misc errors.

For example, I some times get findstr file not found...

I need to improve this batch file so the simultanious execution is faster, without the errors.

Thanks,
Rene

@ECHO OFF
SETLOCAL EnableDelayedExpansion

SET LogFile=%~n0.log
SET TmpFolder=%~dp0%~n0_TMP

IF EXIST "%TmpFolder%" RD /s /q "%TmpFolder%"
IF NOT EXIST "%TmpFolder%" MD "%TmpFolder%"
IF EXIST "%LogFile%" DEL "%LogFile%"

FOR /F "delims=" %%T in ('TIME /t') DO SET TheTime=%%T

FOR /F "delims=\ " %%A IN ('NET VIEW ^| FINDSTR -i "\\" ^| FINDSTR -i -v "%computername%"') DO (
	SET BatchFile=%TmpFolder%\%%A.bat
	ECHO %%A
	ECHO psexec \\%%A cmd /c time %TheTime%>>"%LogFile%"
	ECHO psexec \\%%A cmd /c time %TheTime%>>"!BatchFile!"
	ECHO EXIT>>"!BatchFile!"
	START "SET NETWORK TIME" /min "!BatchFile!"
	PING -n 1 -w 10 10.0.0.0 >NUL
)

EXIT

Open in new window

0
Comment
Question by:ReneGe
  • 2
4 Comments
 
LVL 69

Assisted Solution

by:Qlemo
Qlemo earned 200 total points
ID: 37712429
Firstly, that sounds like a bad idea, as you will set the time on those machines no matter how long ago you determined its "template" value. Why don't you just execute a net time command on those machines?

To be honest, I do not get why the ping should change the behaviour of the FOR, as the command pipe is run first, and the FOR loop itself not run before the command pipe is finished.

I would just generate a list of PCs for psexec, and run that asynchronously. However, you loose the logging.
@ECHO OFF

NET VIEW | FINDSTR -i "\\" | FINDSTR -i -v "%computername%"' > %tmp%\pcs.txt
psexec -d -n 5 @pcs.txt net time \\%computername% /set
EXIT /b

Open in new window

0
 
LVL 10

Author Comment

by:ReneGe
ID: 37712634
Thanks Q for your help.

I did try "NET TIME \\TIMESRV /SET /YES".

But the time on few non domain controller servers, keeps going back to + or - 1h.

PS: We are located at -5 GMT and time shifted 1h this weekend.

Have any ideas?

Cheers,
Rene
0
 
LVL 84

Accepted Solution

by:
oBdA earned 300 total points
ID: 37713418
Doing that manually won't help anything; AD has a time sync hierarchy which will (and should) in all likelihood be more persistent than you.
Make sure the latest DST patches are applied to the systems that show this behavior. As a quick workaround, you can download the tzedit.exe tool from the link below and verify/correct the time zone settings manually on those machines.
How to configure daylight saving time for Microsoft Windows operating systems
http://support.microsoft.com/kb/914387
And btw: "net time" is utterly deprecated. It's NetBIOS based and queries the browser list for a DC, not the AD hierarchy.
w32tm /resync /rediscover
would be the correct way to force a client to update its time.
0
 
LVL 10

Author Comment

by:ReneGe
ID: 37714507
Case resolved :)

http://support.microsoft.com/kb/2633952 + w32tm /resync /rediscover

Thanks Q and oBdA

Cheers,
Rene
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

679 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