troubleshooting Question

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

Avatar of PAdocIT
PAdocITFlag for United States of America asked on
ProgrammingScripting LanguagesWindows Batch
5 Comments1 Solution495 ViewsLast Modified:
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=)

Steven Carnahan
Assistant Vice President\Network Manager

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros