Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

BatchFile: Simultanious execution

Posted on 2012-03-12
4
Medium Priority
?
258 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 71

Assisted Solution

by:Qlemo
Qlemo earned 800 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 1200 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
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 summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

876 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