I have two mapped network drives on my windows machine, from a NAS. Both drives require the same username/password configuration, and I opted not to tell windows to remember this, because well, I want the bare minimum requirement for accessing any of my files should be at least entering one password right, right?

Because of this, Windows will not connect the network drives on login and gives me the usual error: Could not reconnect all network drives

To no one's surprise, windows has no idea what to do when it doesn't know the password to my network share.

So here is how I want to automate this process: After booting up and logging in, I want to get a network login popup window, like the one you get when you try to access a window. I want to log in successfully, and then I want Windows to try and connect the network drives.

How would I achieve this?

(I am well aware that I could use the same username and login on my Windows machine as the network login to automate this, but I don't want to do that either, even if it is what I would normally recommend to others)


I tried achieving this with my basic batch skills. Here's what I came up with.

First configure windows to launch folder windows as a separate process (rather than keeping all folders under the same explorer.exe) this allows folders to be closed via command prompt/batch scripts.

Enable folders as separate processes

Next write this batch file, and place it in **C:\Users\Username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup** (Why is this not bold lettered?)

@echo off
start explorer "D:\"
timeout 0
(net use | findstr OK) > nul 2>&1
if errorlevel 1 goto loop
taskkill /F /FI "WINDOWTITLE eq NETWORKDRIVELABEL*" /IM explorer.exe
start /wait explorer "G:\"
timeout 0
taskkill /F /FI "WINDOWTITLE eq NETWORKDRIVE2LABEL*" /IM explorer.exe
start /wait explorer "F:\"
timeout 0
taskkill /F /FI "WINDOWTITLE eq NETWORKDRIVE3LABEL*" /IM explorer.exe
start /wait explorer "H:\"
timeout 0
taskkill /F /FI "WINDOWTITLE eq NETWORKDRIVE4LABEL*" /IM explorer.exe

Simply replace the drive letters with the ones that apply to your system, and the NETWORKDRIVELABEL with the names of the appropriate network drives. This is needed because the full name of the window title is "NETWORKDRIVELABEL (\SHARENAME) (DRIVELETTER)" but instead of writing a complete window title I simply use a star (*) to define that it is meant to close any explorer process with a window title starting with NETWORKDRIVELABEL.

What this does is it tries to open network share "D:\" with windows's file explorer. As it does since it's a network share you get the prompt to log in. Afterwards a loop is run where the program runs net use | findstr OK (looking for "OK" in the output of "net use") and does not move on until it finds an OK (This part assumes that you have no network drives initialized. I'm not sure how to be more elaborate with findstr; it is not as nice as bash's grep).

Then as soon as it detects a network drive is properly connected, it will proceed to try and map the other network drives by way of opening them with the explorer and then closing them.

I had to use the stop command at the end of the batch file or it wouldn't end normally (waited for user input).

Refer to here if you want to do this but hide the command window: How to run a batch file without launching a "command window"?

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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