Solved

BatchFile: Simultanious execution

Posted on 2012-03-12
4
250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 70

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 85

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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