问题
often i have to create map drive where i specify machine and user credential. now i like to know can we write a batch file which will create map drive and where i provide all details like pc and folder location and user credentials etc. i got one as follows but i think this is not one which i require. please guide me. thanks
net use \\<network-location>\<some-share>\ password /USER:username
@echo Create new L: drive mapping
@net use L: \\network path /persistent:yes
@echo Create new K: drive mapping
@net use K: \\network path /persistent:yes
:exit
if i do this way...then does it work
net use y: \\192.168.7.15\$D\testfolder password /USER:username /PERSISTENT:YES
please guide.....the syntax is ok?
回答1:
Answer of the Mou's query: If a map drive called Z exist in that pc then what will happen? can we write batch file like if a specific map drive exist then disconnect it and reconnect it again.
The solution of this problem is that You can simply map the share without assigning a drive letter. It is then mapped anonymously, only by its remote UNC path. This way you can also remove the mapping by specifiying only its remote name.
@echo off
net use \\192.168.7.15\testfolder password /user:domain\username /savecred /p:yes
REM Do your stuffs here.....
net use \\192.168.7.15\testfolder /delete
Answer of the Thomas's query: How to disconnect and connect map drive by batch file.
If you simply want to disconnect and re-connect a map drive, do like this:
@echo off
net use z: /delete
net use z: \\192.168.7.15\testfolder password /user:domain\username /savecred /p:yes
回答2:
I presume your testfolder is shared then do like this:
net use z: \\192.168.7.15\testfolder password /user:domain\username /savecred /p:yes
来源:https://stackoverflow.com/questions/23294761/how-to-create-map-drive-by-batch-file