Calling variables from a text file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Crawfy
Posts: 1
Joined: 06 Jun 2018 22:20

Calling variables from a text file

#1 Post by Crawfy » 06 Jun 2018 22:27

I have created a simple batch file to open Windows Explorer of a remote PC.
I would like a way to create a list in a text file of all the remote PC names i need to access then run the batch file to open all of them in separate windows.
Is this possible?

At the point the batch file asks for user input, I would prefer it refer to a text file, or even a list within this batch file, for the PC names. I will constantly edit the names and quantity as time goes on.

Code: Select all

@echo off

:: File to open Remote PC C drive locations in a separate Windows Explorer window

: Beginning
:: ask for PC name
echo.
:: SET /P _inputname= Enter remote computer name:
echo.

:: Launch explorer, \\PC name\c$
echo.
echo Opening Remote C Drive
start %SystemRoot%\explorer.exe \\%_inputname%\c$ 

goto :Beginning

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Calling variables from a text file

#2 Post by penpen » 08 Jun 2018 02:43

If the remote pc names don't use problematic characters, then you could use a for/f loop; "test.bat":

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion
for /f "usebackq delims=*" %%a in ("RemotePcList.txt") do (
	echo(Remote pc: %%~a
)
"RemotePcList.txt":

Code: Select all

PC1
PC2
...
PCX
Result:

Code: Select all

Z:\>test.bat
Remote pc: PC1
Remote pc: PC2
Remote pc: ...
Remote pc: PCX
penpen

Post Reply