This page is edited from the 1cmdfaq.txt faq-file contained in
my tscmd.zip
command line interface (CLI) collection. That zipped file has much
additional material, including a number of detached .cmd script
files. It is recommended that you also get the zipped version as a
companion.
Please see "
The Description and
the Index page" for the conditions of usage and other such
information.
184} How do I map a network drive from the command line?
For example:
@echo off & setlocal enableextensions
net use s: \\192.168.1.2\COMP2_DTEXT /user:whoever
xcopy /v/f C:\_D\MyTexts\MyFile.txt s:\
dir s:\
net use s: /delete
endlocal & goto :EOF
The output might be e.g.
C:\_D\TEST>CMDFAQ.CMD
The command completed successfully.
C:\_D\MyTexts\MyFile.txt -> S:\MyFile.txt
1 File(s) copied
Volume in drive S is COMP2_C
Volume Serial Number is E753-B1B6
Directory of s:\
11.03.2011 12:23 <DIR> .
11.03.2011 12:23 <DIR> ..
11.03.2011 12:33 34,062 MyFile.txt
1 File(s) 34,062 bytes
2 Dir(s) 38,304,260,096 bytes free
s: was deleted successfully.
The last message is slightly misleading because s: actually is not
deleted, but disconnected.
The next question is whether a
net use
mapping is the best option. Another method is just a simple
environment variable assignment:
@echo off & setlocal enableextensions
set s_=\\192.168.1.2\COMP2_DTEXT\
xcopy /v/f C:\_D\MyTexts\MyFile.txt %s_%
dir %s_%
set s_=
endlocal & goto :EOF