Solved

BatchFile: Simultanious execution

Posted on 2012-03-12
4
245 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 68

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 83

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now