question

SzymonRabiza-7107 avatar image
0 Votes"
SzymonRabiza-7107 asked BosunDoug-5586 answered

How to delete the old network drive and add new one with one command in cmd?

Hello,
How could I delete the old network drive and add the new with one command in cmd, is this even possible ?

Best Regards

windows-serverwindows-10-network
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LeonLaude avatar image
1 Vote"
LeonLaude answered LeonLaude commented

Hi @SzymonRabiza-7107,

To add and delete a network drive with cmd you can make use of the net use commands.

net use z: /delete && net use z: \\servername\share


If the reply was helpful please don't forget to upvote and/or accept as answer, thank you!


Best regards,
Leon

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @LeonLaude
Thank you for the answer, but is there a command that check if network drive is still shared and if not, he is deleted, and new one if is shared is added?

Best Regards,
Szymon

0 Votes 0 ·

You can only check if the mapped network drive is already mounted, not sure if you can check if it's in use.

0 Votes 0 ·
JiangZhang-MSFT avatar image
0 Votes"
JiangZhang-MSFT answered JiangZhang-MSFT edited

Hi,
You may refer to LeonLaude’s answer: net use z: /delete && net use z: \\servername\share.

Best Regards,
Mulder Zhang


If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

BosunDoug-5586 avatar image
1 Vote"
BosunDoug-5586 answered

Hello, @SzymonRabiza-7107 and all.
Further to the archived thread at <https://social.technet.microsoft.com/Forums/en-US/f4460a73-6a42-47f8-950b-2f18e03c0a7e/impossible-to-remove-a-persistent-network-drive-mapping-when-logged-on-disconnected?forum=win10itprogeneral>; and the above answers; you may wish to use the following commands.

Net Use z: /Delete
Mountvol z: /d
if not exist z:\ (Net Use z: \\servername\share /Persistent:YES)

These three lines can be concatenated into a single command line expression, by using ampersands (&).

I have struggled for the last six months and have developed an elaborate batch file to remap my home network drives on my laptop; as Windows 10 doesn't always find them again. Today, the referenced archived thread pointed me to using both Net Use /d and Mountvol /d — as a pair. Kudos to @JackJack and @Grajon, as the net use and mountvol pair obviates the need to stop and restart file Explorer; which itself introduces other (potential) issues!

Best regards,
BosunDoug

PS. Per the original/archived thread, I too suspect this is an unresolved Windows 10 bug.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.