Avatar of PAdocIT
Flag for United States of America asked on

Is it possible to use %InputFile% with net use?

I am trying to setup a batch file that will loop though a text file of IP's and basically map a drive, copy some files, unmap the drive, and move on to the next IP in the list.

This is a script i use for batch copying but trying to add the net use command seems to break it. The reason for net use is because the location of the folder is on C: and is not shared. So I am trying to connect through the C$ admin share and pass credentials.

I keep getting system error 67 has occurred network name cannot be found. Net use with the IP and path works fine so I know my path is good. I believe the problem to be the input file is not working so the path does not get created properly.

If an input file doesn't work with net use. Is there an alternative way to achieve the same results?

Below is the script:
@echo off

(Set FileSource=D:\Folder\Folder\*.txt)
(Set RemoteShare=C)
(Set RemoteDestinationFolder=Folder)

(Set InputFile=D:\Folder\File.txt)

(Set RemoteDestination=\\%%*\%RemoteShare::=$%\%RemoteDestinationFolder%)
For /F "eol=;" %%* in ('type "%InputFile%"') do (
 Ping.exe -n 2 -w 750 %%* | Find/i "TTL=" >Nul | net use X: \\"%InputFile%"\C$\Folder /user:Username "Password"&&(
 xcopy /y "%FileSource%" "%RemoteDestination%" | net use /delete X: >nul | echo.%%*) || (
  echo.%%* "Computer was Not found">>%InputFile%.errors.log)
 If Not ErrorLevel 0 echo.%%* "Copy was unsuccesfull">>%InputFile%.errors.log
 (Set ErrorLevel=)


Open in new window

Windows BatchProgrammingScripting Languages

Avatar of undefined
Last Comment

8/22/2022 - Mon

try reading the file and obtaining the ip and storing it in a variable before providing the content to the command.  instead of using the %inputfile% and passing the whole thing, read the one specific line into a variable and provide only the variable to the command.
Steven Carnahan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question


should be net use X:\\%%*\C$\Folder

Steven Carnahan

Glad I could help (I think)  :)

Sometimes it just takes that extra set of eyes.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes

You did. The for  /f is looping through the txt file and outputting the IPs to a variable of %%*. That was the variable i needed not %InputFile%. As soon as you pointed out what was happening, I put hand to forehead. lol. Thanks again.