41

When a network drive (net use) is physically disconnected, Windows Explorer (and other programs) keeps trying to enumerate and/or use it for maybe 60 seconds.

Is there some way to reduce this timeout to maybe 5 seconds?

Just to clarify, I'm not asking about network drives that are automatically disconnected by Windows after a certain period of time, or about automatic reconnections during login.

The question is about this:

Connect a network drive to another computer. Then turn that other computer off. Then try to reconnect the network drive, e.g. by double-clicking in Windows Explorer → very long timeout. How do I reduce this timeout?

7 Answers7

5

In Windows 7 and Vista mapped network drives will disconnect themselves after a time and show a red cross on the drive icon. You will still be able to click on the drive and see/use the contents but applications that require a network drive will see them as disconnected and will not see files. If you try to disconnect the drive, it will still sit there saying 'Disconnected Network Drive' - the only solution is to reboot. This is because there is a default disconnect time for inactive network connections. To correct this and turn the autodisconnect off do the following:

  1. Open the command prompt as Administrator. To do this, either:

    • go to Start → All Programs → Accessories, right-click "Command Prompt" and select "Start as Administrator", or

    • type cmd into the search box and press Ctrl+Shift+Enter

  2. In the command prompty, type the following:

    net config server /autodisconnect:-1
    
  3. Press Enter

  4. Reboot computer

Your mapped network drives should now stay connected - this is a permanent fix.

Indrek
  • 24,874
Krishna
  • 75
4

This worked to me on Windows 7 as expected. Also it solves a long wait after login. Pasted here as a .reg file:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider]
"RestoreConnection"=dword:00000000
"RestoreTimeout"=dword:00000004
"DeferConnection"=dword:00000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\LanmanWorkstation\Parameters]
"SessTimeout"=dword:0000000a
"ExtendedSessTimeout"=dword:00000000
"ReconnectTimeout"=dword:00000004
3

Based on https://web.archive.org/web/20140916223632/http://blogs.msdn.com/b/openspecification/archive/2013/03/27/smb-2-x-and-smb-3-0-timeouts-in-windows.aspx, it looks like the Windows share timeout is controlled by the "Request Expiration Timer" registry entry.

\HKLM\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters\
Value type: Dword  
Value name: SessTimeout
Default:    60 seconds (Windows Vista)

It also mentions that this value was reduced to 20s in Windows 8 for quick failover with SMB 3.0.

AJM
  • 500
3

I was having the same problem, but initially it was only around 30 seconds. But when it jumped to around 2 minutes (for some unknown reason), it got so annoying, I had to find a way to solve it.

I have created batch script which tests the network by seeing if it can ping the target machine, if it can, it maps the drives (if unmapped), otherwise, it deletes the mapping.

@echo off

set ipaddr=192.168.5.3

set current=neither

:begin

    set state=down

    for /f %%i in ('ping -n 1 %ipaddr% -w 1000 ^| findstr /C:"Received = 1"') do (
        set state=up
    )

    if not %state% == %current% (
        set current=%state%
        if %state% == up (
            net use R: \\%ipaddr%\archive$
        )
        if %state% == down (
            net use R: /delete /y
        )
    )

    sleep 5

goto begin

That script is then called by a scheduled task, which runs the script every 10 minutes, with a maximum task time of 10 minutes. Although the console window then remains open during this time, I am currently investigating the Network Conditions for this in the scheduler settings, which could be set to create the shares when connected to the network I know the share is on (which would set a flag), and a second script, which would run once ever 5 minutes or so, which if the flag was older than at least however long, it would delete the shares, minimizing console window time.

topherg
  • 1,150
2

Your solution is below;

Kill the long "restoring network connections" at logon (defer=ghosted connections)

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider]

"RestoreConnection"=dword:00000001 ;(0=no attempt, you must click it)

"RestoreTimeout"=dword:00000005

Ghost the connection if not responding within RestoreTimeout

"DeferConnection"=dword:00000001
Kevin Panko
  • 7,466
0

waiting for unavailable network drives. I created the above keys and set their values, but I'm still waiting the same ~30 seconds (Windows 7) <<

I have been bashing my head against it in Win10 with the difference that the timeout **has increased from 30 sec to five minutes.

This seems to work

netsh interface tcp set global initialRto=300

300 appears to reset it to 30sec ...and that appears to be the minimum setting allowed .

In any case, 30 sec compared to 5 minutes is a huge improvement.

Since it is TCP related, I'm expecting that it may be too short for other internet related timeouts and expect to be fiddling with over time.

Ramhound
  • 44,080
-1

According to this post on Windows7Hacker, fixing this issue on the client side involves a registry edit.

  1. Open the Registry with Regedit.exe
  2. Naviagate to HKLM\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters
  3. Create a DWORD value named KeepConn and set it to time in seconds to keep the connection alive

For example, I set it to 86400 (one day).

deppfx
  • 187