Can anyone see what's wrong with my script?

Soldato
Joined
23 Nov 2004
Posts
3,794
My below script doesn't seem to be looping for all entries in devices.ini. It should loop and repeat the script for every entry (device dns name) in devices.ini but it only does the first entry and then the script closes. I'm guessing it's because of the GOTO statements? Anyone shed any light why and how I can get around it?

Thanks

Code:
@echo off
FOR /f %%i in (devices.ini) DO (

ECHO -----------------%%i----------------- >>Results.txt
ECHO. >>Results.txt

NET USE /D N:
CLS


ECHO 			##################################
ECHO 			##  MARS RPBE Client Installer  ##
ECHO 			##          Version 1.0         ##
ECHO 			##         By Matt Page         ##
ECHO 			##################################
ECHO.

ECHO Connecting to %%i...
NET USE N: \\%%i\c$ /USER:XXXXXXXX
CLS
IF NOT %ERRORLEVEL% == 0 GOTO MAPFAIL

ECHO Installing MARS on %%i
ECHO PLEASE WAIT...
XCOPY DRSAPPS\*.* N:\DRSApps /S /E /C /I /Y
IF NOT %ERRORLEVEL% == 0 GOTO COPYDRSFAIL

CLS

ECHO Creating Food Services folder on stores desktop...
IF NOT EXIST "N:\Documents and Settings\Stores\Desktop\Food Services" GOTO FOLDER
GOTO ICON

:FOLDER
MKDIR "N:\Documents and Settings\Stores\Desktop\Food Services"
GOTO ICON

CLS

:ICON
ECHO Copying Shortcuts to Food Services folder for Stores user...
XCOPY "\DRSApps\MARS LIVE.lnk" "N:\Documents and Settings\Stores\Desktop\Food Services" /S /E /C /I /Y
XCOPY "\DRSApps\MARS TEST.lnk" "N:\Documents and Settings\Stores\Desktop\Food Services" /S /E /C /I /Y
IF NOT %ERRORLEVEL% == 0 GOTO COPYICONFAIL
GOTO SUCCESS

ECHO %%i
PAUSE

:MAPFAIL
ECHO Failed to connect to device >>Results.txt
ECHO Aborting Installation >>Results.txt
ECHO Moving to next device... >>Results.txt
GOTO FINISH

:COPYDRSFAIL
ECHO MARS RPBE Client Installation failed >>Results.txt
ECHO Aborting Installation >>Results.txt
ECHO Moving to next device... >>Results.txt
GOTO FINISH

:COPYICONFAIL
ECHO MARS Icon creation failed >>Results.txt
ECHO Aborting Installation >>Results.txt
ECHO Moving to next device... >>Results.txt
GOTO FINISH

:SUCCESS
ECHO Successfully Installed MARS RPBE Client >>Results.txt
ECHO Moving to next device... >>Results.txt

:FINISH
ECHO. >>Results.txt
ECHO ----------------------------------------- >>Results.txt
ECHO. >>Results.txt
ECHO. >>Results.txt
)
 
Post the contents of devices.ini aswell.

It's just got a device names (DNS) in it, one per line. Only two in there at the moment but I was going to put in 50 odd. Just saves me time, I can put all device names in the devices.ini and leave it running.

Contents of devices.ini are:

Code:
MANTRN06
MANTRN07
 
01: Has this script ever worked before?
02: Where it says '
ECHO Creating Food Services folder on stores desktop...' - are all users on every desktop called 'stores'?

I don't think I would have wrote it like that if the workstations never change their name I would have just manually put them into the script without a .ini then in that case you would have known where the problems where.

Get one working then just copy the script over n over. Atleast that way you know it's going to work rather than loop.
 
01: Has this script ever worked before?
02: Where it says '
ECHO Creating Food Services folder on stores desktop...' - are all users on every desktop called 'stores'?

I don't think I would have wrote it like that if the workstations never change their name I would have just manually put them into the script without a .ini then in that case you would have known where the problems where.

Get one working then just copy the script over n over. Atleast that way you know it's going to work rather than loop.

Yes, it's the same user for every PC. It will be going out to hundreds of devices and I don't want to be copying it numerous times.
I've written lots of scripts in the same method and they work fine. The only thing I can think why it wont work is because of the GOTO statements?

The device names never change but each site has a different first 3 letters odf the device name. EG devices in Wimbledone would be WIMXXXXX, etc.
 
Code:
@ECHO OFF
ECHO Delete Drive Mapping
NET USE /D N:
CLS

ECHO Connecting to Workstation...
NET USE N: \\MANTRN01\c$ /USER:XXXXXXXX
CLS

ECHO Making Folder...
MKDIR "N:\Documents and Settings\Stores\Desktop\Food Services"
CLS

ECHO Copying Shortcuts to Food Services folder for Stores user...
XCOPY "MARS LIVE.lnk" "N:\Documents and Settings\Stores\Desktop\Food Services" /S /E /C /I /Y
XCOPY "MARS TEST.lnk" "N:\Documents and Settings\Stores\Desktop\Food Services" /S /E /C /I /Y

EXIT

^^^ Test this on a workstation and then just repeat? If it works then it's simply copy n paste or create single batch scripts for xxx device.
 
Yes, it's the same user for every PC. It will be going out to hundreds of devices and I don't want to be copying it numerous times.
I've written lots of scripts in the same method and they work fine. The only thing I can think why it wont work is because of the GOTO statements?

The device names never change but each site has a different first 3 letters odf the device name. EG devices in Wimbledone would be WIMXXXXX, etc.

ah I see, hum in that case theres few script gods on here that may pop along at some point. Will still give it a bash here in few test environments to see whats going on.

ah wait......
I see on the line :SUCCESS, where is it's loop back to the start?
 
Last edited:
ah I see, hum in that case theres few script gods on here that may pop along at some point. Will still give it a bash here in few test environments to see whats going on.

ah wait......
I see on the line :SUCCESS, where is it's loop back to the start?

The FOR loop should loop until it has reached the last entry in devices.ini

All of my other for loop scripts work fine, but it seems the GOTO statements mess it up. The only reason I've got the GOTO statements is for error checking.

Can you think of another way of doing this?
 
The FOR loop should loop until it has reached the last entry in devices.ini

All of my other for loop scripts work fine, but it seems the GOTO statements mess it up. The only reason I've got the GOTO statements is for error checking.

Can you think of another way of doing this?

Turn error checking off maybe? Do you really need all of that sort of logging maybe just log it once to results.txt within the C drive without outputting it onto the screen on copy.
 
Putting the for loop in another batch file and then calling the original batch file works, although you have to change the variable name in the second batch file from %%i to %1
 
Back
Top Bottom