Saturday, 7 January 2012

Could Not Reconnect All Network Drives in Windows 7

I often see the notification balloon popping up from system tray to tell me that my network drives could not reconnect. I typically see this after I've first turned on my computer or after I've booted from Hibernation.

When I open Computer, I can see my network drives, but they are shown with a red cross indicating that there is indeed a problem with the connection to them. Applications which rely on data from these network drives cannot obtain their data, and fail in their own ways. The particularly annoying aspect of this is that there absolutely no problem with the network connection to these drives. Simply double clicking on the drives will open them up and restore the connection. All applications will function correctly thereafter... until the next time I boot up the machine.

Below is a workaround you can use to ensure your remote drives are available for use when you turn on your PC. For my environment, I'm running Windows 7 64-bit and have a Synology DS411J which is a NAS drive. But really, this should work for connecting any remote network drive.

The trick to getting around this is to tell Windows to map your network drive every time your computer boots up. It turns out this is quite easy to do. All you have to do is write a script which, when executed, will reconnect your network drive and then set up a task to run the script when the computer starts up. Mapping a drive simply means that in Computer, a drive, with a drive letter - say Z: - so that whenever you refer to a location on the Z:, Windows will actually look at the network location mapped to that letter.

Creating the Script
You want to create a Windows Batch File (which has a .bat filetype) which will serve as your script. You need to know at this point which drive letter you will be using for this network drive. I use z: in the following example. You will also need to know the location on the network that you are wanting to map a drive to. In the following example, I am accessing \\DISKSTATION\Media folder which is on my NAS drive.

In the following example, I first remove the drive and then add a new one in. I do this just in case any other folder has stolen the Z: somehow. I always want to be able to depend on the Z: having my media so I find it better to remove first, then re-add.

  1. Create a new file which has a .bat file extension
  2. Give it a name (MapDrives.bat for example) and put it somewhere you'll remember.
  3. Open this file in Notepad.
  4. Add the following lines:
    • net use z: /Delete
    • net use z: \\DISKSTATION\Media
  5. Save and close the file.
  6. Double click the file and make sure your drive appears in Computer as you'd expect. If you can't see the new drive:
  • Check you can actually reach the network location. 
  • Edit the script, and add the word pause on a new line, after your other two lines. Run the script again and it should tell you if there was an error.
Your script should resemble the following:


Running the Script

Now that you have a working script, you need a way to get this script to run automatically. You could put it in your startup folder, but I prefer to use the built-in Task Scheduler.

  1. Open Task Scheduler
    • If you can't find it, enter %windir%\system32\taskschd.msc /s into your Run command.
  2. On the right hand side, under Actions, click Create Task...
  3. Name your task something sensible: Map Network Drives for example
  4. Click the Triggers tab
  5. Click New... button
  6. Add At startup
  7. Under Advanced Settings, select to delay the task for 30 seconds.
  8. Repeat to add another trigger, this time add On workstation unlock - you may wish to add a delay here too although mines is working without doing so (See the Triggers screenshot below for an example)
  9. Click the Actions tab
  10. Click the New... button
  11. Click the Browse... button and find your .bat file. (See the Action screenshot below for an example)
  12. Click OK button, then click the OK button to create the Task.
  13. Click on Task Scheduler Library from the left pane, and check that your new task is in the list of tasks. If you can't see it, right click in the task list and click Refresh.
  14. Click on your task, then click Run from the Actions pane.
  15. Check Computer, to make sure your drives are there. If you want, right click and disconnect the drive to do a proper test. Once removed, go back to Task Scheduler, and click Run again.
That is you all set up to go. Restart your computer and make sure your drives are still available to you.

Note, you might still see the balloon popping up telling you there was a problem connecting to your drives, as that 30 second delay might not have happened by that point. You can disable this balloon notification if you so choose. When you see it, click on the spanner icon, and select Hide icon and notifications.

Any problems? Not working for you? Steps missing? Let me know in the comments below!





  1. Thanks Craig.

    I've had this problem on Windows 7 and now on Windows 8. I was hoping that MS would fix it, but alas...

    I have a ReadyNAS Duo v1, which has 3 shares on it, so I had to repeat the USE NET commands 3 times, once per share. It all works fine.

  2. Craig,

    Thanks a million! tried tinkering around with registry settings and a thousand other things but without avail.. until I found your blog.

    Thanks again, Patrick.

  3. Great advice! However I am having the problem that the scheduled task fails because it is trying to run with the current user account. It sees the network as unavailable until accessed. Could you suggest a way that would make the network be accessed before trying to run this task? It seems that until then this will not work properly.

  4. Oh man I like this.... plus I was able to find spyware or bad stuff still in my task manager that was never removed. Thank You so much Craig and great advice...and it worked! :-)

  5. Everything works well - the only problem I am having is that the NAS drive needs a username PW to log on. How can I alter the script to include that?

  6. While the article is helpful, let's face it: the real trick is to get Windows to do what it's supposed to do, which is reconnect the drives AFTER the network is available so we don't see errors that reflect bad programming. The OS is misbehaving, and we all have to write and execute scripts to get around it?

    1. Anonymous I don't like having to do things like this either. But as I have no control over the development of the Windows OS but mostly like using it, this is the position I find myself in.

  7. Found a solution on Microsoft's website:

    Start > Run > type "gpedit.msc" (without quotes) click ok.

    Local Computer Policy > Computer Configuration > Administrative Templates > System > Logon > Always wait for the network at computer startup and logon

    set this to Enable then reboot.

    this solved the annoyance for me.

    1. This looks interesting, I'll check it out later, thanks.

      What happens when the network is down, or slow, does it affect boot time of the computer?

    2. Tried this a long time ago, and it has been ineffective for me.

    3. Ineffective for me as well. And this just started for me recently. New AV - BitDefender, new Office 365 and new version of Timeslips Billing software - gotta be in there somewhere..

  8. This is great advice spelled out for noobs like me.. and works! It took me ages to find this fix and MS support was useless.

  9. Is there a way to get the batch job to run with its window minimized? Otherwise, it's a cool little fix.

  10. In my home environment, I think that upon reboot, it may be taking a while for the WiFi network connection to stabilize, and Windows may be trying to make the (re)connections before the network is available to the PC...

    I've noted this issue with a Backup App that tries to run before it can "see" the Backup space on the NAS. I resolved this by delaying startup of the backup App for 5 minutes after startup (via WinPatrol).

    Similarly, a delay may help before attempting to re-connect the Mapped Drives. I'll try your batch file, incorporate a delay before it executes, and see what happens.

    I will be really happy if ALL Mapped Drives are fully functional once the PC has completed it startup processes.