For example, when I type net use I might see something like:

Status        Local       Remote
OK            H:          \\server\home folders\me
Unavailable   I:          \\serverA\share1
Disconnected  J:          \\serverB\share2
Reconnecting  K:          \\serverC\share3

When this happens, Windows Explorer has 10 - 20 second delays when doing something as simple as creating a new folder on my C: drive. After a while, the K: drive will change to say "Disconnected".

What I want to do is somehow force the K: drive to be Disconnected or Unavailable, but without losing the authenticated mapping.

  • 2
    Just out of curiosity, why do you think you need this? – Zoredache Oct 29 '13 at 18:47
  • 2
    I connect to a VPN, use the K: drive, then disconnect the VPN. After that, my Explorer is often slow, until it finally marks K: as disconnected. This is a simplification, as I have more than 3 drive mappings needed by various scripts, and may connect/disconnect from the VPN multiple times a day. – Glen Little Oct 29 '13 at 20:12
  • 1
    @GlenLittle Have you tried unchecking the "reconnect at logon" option when you map the drive? – user201262 Oct 30 '13 at 2:09
  • 4
    Why not make a script to connect and disconnect the drives (including removing the mapping). Like here You could even create a script which connect to the VPN automatically and a script to disconnect (including all the drive-mapping stuff) – Rik Nov 1 '13 at 22:18
  • 4
    A net use \\serverB\share2 /delete should do the trick (it disconnects the drive but doesn't afflict the mapping) – Paolo Gibellini Nov 7 '13 at 7:28

Microsoft seems to be trying to move administrative tasks such as this to PowerShell.

In your specific case, the cmdlet to use is Remove-PSDrive. Remove-PSDrive will do exactly what you are asking for: disconnect a mapped network drive. The syntax for your scenario would be:

Remove-PSDrive -Name K

To get to a powershell command line where you can run that cmdlet, open the start menu, and in the search box just type powershell. If you don't have the search box, then from the start menu select Run and in the run box type powershell and press enter.

For full details on how to use this cmdlet including all of it's options see Microsoft's technet article:

| improve this answer | |
  • Sounded very promising, but doesn't work for me. If I do net use y: ...., then start PowerShell and do get-psdrive, I see Y listed. Doing remove-psdrive -Name Y removes it. But then a net use still shows it, and I can still use the Y: drive. (That was using PS v2. Apparently works with v4.) – Glen Little Nov 13 '13 at 22:30
  • Powershell 4.0 was released a couple of weeks ago... technet.microsoft.com/en-us/library/hh847820.aspx – Glen Little Nov 13 '13 at 22:42
  • @GlenLittle But does this remove the drive-letter or disconnect it while keeping the letter? If it removes it, isn't this the same as net use Y: /delete? – Rik Nov 13 '13 at 22:55
  • Finally able to try it. Unfortunately, this seems to mimic Net use /delete as @Rik guessed. I don't see a difference, as far as network drives are concerned. – Glen Little Nov 15 '13 at 20:25

Ok. I might have a solution. I tried looking into the /savecred parameter of net use but couldn't get it to work properly so here is another approach:

Your trouble was the delay with Explorer after the disconnect with the VPN.
So why not hide the drives from Explorer after the disconnect so it won't try to access them.

There is a registry key to hide drives from Explorer:



Below this post there is a summary as to what value NoDrives should hold.
(add the numbers for the drives).

I've created a small batchfile where you don't have to do the calculations yourself.
It is a 'toggle'-batchfile.

Run it once to connect to your "My VPN".
Run it again to disconnect and hide the drives I, J and K.

You can easily split this in two batchfiles but you get the point... You could also simplify this batchfile if you set the number of NoDrives yourself instead of letting the batch do the calculation.

This needs to be run as administrator. (it is possible to automatically elevate but that's very advanced)

If you grant yourself permission on the key NoDrives you don't have to run this as administrator. Just open up regedit.exe, browse to this key and click "Edit > Permissions" and grant yourself "Full Control" over this key.

@echo off
:: ------------------------
set MyVPN="My VPN"
:: ------------------------
rasdial | findstr %MyVPN% 1>nul
If %ERRORLEVEL% == 0 goto disconnect

echo ============================================================
echo connecting to %MyVPN%
echo ============================================================
rasdial %MyVPN%
:: This is easy. We just set 0 in NoDrives
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer /v NoDrives /T REG_DWORD /d 0 /f

goto :end

echo ============================================================
echo disconnecting from %MyVPN%
echo ============================================================
rasdial %MyVPN% /disconnect

:: ------------------------------------------------------------------
:: This is harder. We need to determine what value NoDrives should be
:: ------------------------------------------------------------------
Setlocal EnableDelayedExpansion

:: ------------------------
:: Set here your VPN drives
:: ------------------------
set drives='I J K'

:: ------------------------
:: Calculation to determine the value
:: ------------------------
set drive_value=1
set NoDrives=0
for %%c in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
  echo.%drives% | findstr "%%c" 1>nul
  if !ERRORLEVEL! == 0 set /a NoDrives+=drive_value
  set /a drive_value="drive_value<<1"
echo Seting NoDrives to %NoDrives%
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer /v NoDrives /T REG_DWORD /d %NoDrives% /f


Windows Explorer needs to be closed and opened again before the drives are hidden (or visible again).

Settings for NoDrives:


     Decimal       Hex
A:         1         1
B:         2         2
C:         4         4
D:         8         8
E:        16        10
F:        32        20
G:        64        40
H:       128        80
I:       256       100
J:       512       200
K:      1024       400
L:      2048       800
M:      4096      1000
N:      8192      2000
O:     16384      4000
P:     32768      8000
Q:     65536     10000
R:    131072     20000
S:    262144     40000
T:    524288     80000
U:   1048576    100000
V:   2097152    200000
W:   4194304    400000
X:   8388608    800000
Y:  16777216   1000000 
Z:  33554432   2000000 
| improve this answer | |
  • Looks interesting... I'll have to try this. Love the use of bitwise math in the batch file! – Glen Little Dec 9 '13 at 21:43

I don't know how to do this, but would make a script to add the mapped drive to make life easy.

  1. Create a file with the extension .bat (Ex. map_drives.bat)
  2. Inside the file add a line like this net use J: \\server\folder
  3. Double click on that file and it will map your drive
| improve this answer | |
  • Thanks for the answer. I would do this, but some of the drives need different id/pw authentications, and I don't want to put those into a script. – Glen Little Dec 5 '13 at 4:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.