Link to home
Start Free TrialLog in
Avatar of PAdocIT
PAdocITFlag 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=)
 )

pause

Open in new window

Avatar of firstheartland
firstheartland

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.
ASKER CERTIFIED SOLUTION
Avatar of Steven Carnahan
Steven Carnahan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PAdocIT

ASKER

OMG...duh.

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

Thanks.
Glad I could help (I think)  :)

Sometimes it just takes that extra set of eyes.
Avatar of PAdocIT

ASKER

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.