How to create MAP Drive by batch file
Solution 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
Solution 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
Thomas
i am developer. i am working with .Net technology (v1.1 & v2.0) last 4 year. i like this forum for fast & good response and that is why i joined this forum. my friends profile id Mou :- http://stackoverflow.com/users/728750/user728750?tab=questions and Keith :- http://stackoverflow.com/users/750398/keith-costa thanks
Updated on April 29, 2020Comments
-
Thomas about 4 years
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?
-
jonsinfinity about 10 yearsIs your batch file not working? What errors are you getting?
-
Thomas about 10 yearsi have to pass user id and password but do not know the syntax
-
Thomas about 10 yearsfirst i want to check if the map drive Z is exist then delete it and then create a new map drive called Z with credentials. so need help.
-
Thomas about 10 yearstell me my second one syntax is ok?
-
jonsinfinity about 10 yearsHave you tried what you have? Does it work? If not, what is the error? From a command prompt, type
NET USE /?
to get the syntax.
-
-
Mou about 10 yearsif 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?
-
Thomas about 10 yearscan u tell me how to disconnect and connect map drive by batch file.
-
Sunny about 10 years@Thomas..Please see my second answer.