I want to write a start up script to take an mapped drive, change the drive letter, then put a different share on the original drive. How can this be done?
-
Check out the NET USE command.
You will need to delete the current mapping, then remap with the desired drive letters and shares.
From NYSystemsAnalyst -
net use X: /DELETE net use X: \\newshare
Where
X:
is the drive letter you want to map and\\newshare
is the location of the new share you want mappedFrom Ciaran -
Absolutely.
If for example the existing drive is X: and has \server1\shareA on it and you wanted to remap X: to Y:you could do it with a batch script.
net use x: /delete net use y: \\server1\shareA
If you need to pass credentials you'd have to add the username (and possibly the password if you want it to run totally automated. Note that it's a bad idea to do this with privileged accounts and there are way smarter ways. But for a quick change over this will do it
net use x: /delete net use y: \\server1\shareA <password> /user:<username>
If you don't include the password it will prompt. You can save this in a .bat file and it will run just fine.
EDITED TO ADD more complete solution
So you want to take a drive mapping X: change it to Y: and then connect X: to the new share \server1\newshare? Here you go. You can of course still pass credentials if necessary.
for /F "skip=1 tokens=3" %%i IN ('net use x:') = DO ( set OLDSHARE=%%i goto :DONE ) :DONE net use x: /delete net use y: %oldshare% net use x: \\server1\newshare
The
for
loop parses out the existing share path for the drive letter you want to change. Then you disconnect it from x: reconnect it to y: and then connect the new thing to x: all in quick succession.Bob : Is it possible to pick up the location of the existing share before deleting it?Laura Thomas : You mean determine it from the script? Possibly with a bit of fancy parsing. net use with no arguments returns all the mapped network shares. Net use with only the drive letter returns information including the remote name.Laura Thomas : I edited my answer above. Hopefully this is what you want. It's sort of quick and dirty but it works.Bob : Awesome, thanks a lot!musicfreak : Hmm, I'm trying to figure out what question you answered with "Absolutely". ;)From Laura Thomas
0 comments:
Post a Comment