Solved

BatchFile: Simultanious execution

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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