Can I use  computer name.domain instead of the IP address in the path in a cmd file?

PDSWSS
PDSWSS used Ask the Experts™
on
I have set up a cmd file (attached) that backs up a folder from a local server to a remote server.

I will soon need to change the remote backup location.  The computer at the new location is set up with a dynamic IP and a fixed computer.domain name.   Will the code work if the IP address is replaced with the computer.domain name?


@echo off

:: variables
set drive=\\132.99.188.345\Shared$\Backups\TEST
set folder=Test_%date:~10,4%_%date:~4,2%_%date:~7,2%
set backupcmd=xcopy/s/c/d/e/h/i/r/y

md "%drive%\%folder%"

@echo %backupcmd% "C:\shared$\Test1" "%drive%\%folder%"
%backupcmd% "C:\shared$\Test1" "%drive%\%folder%"

echo Backup Complete!
@pause

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
As long as DNS is working OK and the name can be resolved, then yes it will work.

Commented:
Yes, like roybridge say, meanwhile your server DNS work fine, you should be able to use the computername.yourdomain.local to use shares or another resources.

The only thing to be carefull is if your server have two networks nics with differents ips, this could be a little tricky.

Author

Commented:
When I replace the IP with the computername.domain I get  "Login failure: unknown user name or bad password"

"Invalid drive specification"  

Thanks
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

OK, why not use the "NET USE" command to map a drive to \\computername.domain\share$ then use the "NET DELETE" command when the script has finished...

Author

Commented:
In the code would I just replace  "SET DRIVE" with "NET USE"  ?
no - I would use the NET USE earlier i.e.:-

NET USE X: \\computername.domain\share$ password /user:[domainname\]username

This will map drive X: to \\computername.domain\share$

change the SET DRIVE command to SET DRIVE=X:\backups\test

then near the end of the script

NET USE X: /DELETE

Author

Commented:
Now I get

The Network can not be found
The System can not find the drive specified
xcopy/s/c/d/e/h/i/r/y  "C:\shared$\Test1"   "X:\Backups\TEST\filename"

Invalid Drive Specification
0 File(s) copied

The Network connection can not be found
@echo off

:: variables
NET USE X: \\computername.domain\share$ password /user:[domainname\]username
set drive=X:\Backups\TEST
set folder=Test_%date:~10,4%_%date:~4,2%_%date:~7,2%
set backupcmd=xcopy/s/c/d/e/h/i/r/y

md "%drive%\%folder%"

@echo %backupcmd% "C:\shared$\Test1" "%drive%\%folder%"
%backupcmd% "C:\shared$\Test1" "%drive%\%folder%"

echo Backup Complete!
@pause

Open in new window

Ok just open a command prompt and try the net use command on it's own and let me know the result

Also when you ping computername.domain is the correct IP address returned?

Author

Commented:
Pings back the correct IP

However, "network name can not be found" when I run  NET USE X: \\computername.domain\shared$ password /user:[domainname\]username

Perhaps something off with user domain account?
Can you ping computername instead of computername.domain

Author

Commented:
Yes
Ok so try the net use command and omit the .domainname and see if that works

Author

Commented:
Same error message.
What if you try:-

NET USE X: \\computername\shared$

On it's own

Author

Commented:
Could be a Firewall issue.  The target server Firewall only allows specific  IP connections to File Shares. The IP address of the remote server is in the Firewall. Perhaps won't allow connection via computer name, only IP.

Author

Commented:
Used X:\\computername.domain\shared$

entered username
entered password

This worked -  

Is this the correct format?
password /user:[domainname\]username
If you type

NET USE /?

You'll see the proper syntax for the command
. [domainname\] is optional, and password is obviously replaced with the users password

Author

Commented:
Thanks for your help. Discovered that I needed to leave a space between X:   and     \\computername.domain

Author

Commented:
Thanks again.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial