Most of my company is currently working from home and is having to tunnel into our office network through a VPN. As such, all our network drives are, technically, disconnected until we login to the VPN. Once connected, we could simply open a file explorer window and open each network drive to reestablish/refresh the connection in Windows' eyes, but more than 2 or 3 drives is a hassle, and some of our members don't even think to do this every day even for our main project drive (only universal drive letter we use in our office) before opening some of our programs that need a network drive mapped, and thus have the potential to mess up our files or link therein.
Desired Solution:
I'm looking for a batch or cmd file that can run to refresh or reconnect the drives, without explicitly using NET USE
if possible (more on why further down) or opening a file explorer by using a batch file to open a shortcut to a network folder. If this just isn't possible, I'll stick with the solution I have that uses NET USE
, but would appreciate help smoothing out the issues outlined below.
I have a couple solutions that are more than a little intrusive in that they require some form of interaction to dismiss them once launched, rather than running, reaching eof, then closing using TIMEOUT /T 5
. I was hoping there might be something a little more streamlined, or at least less intrusive, that I could use to avoid these unnecessary interactions that I'm currently dealing with:
Shortcut to a folder on each drive to "ping" said drive for refresh, but this opens a file explorer window, potentially interrupting workflow. I would like to suppress this window opening if possible, or at least immediately close it (not exactly how file explorer works, I know).
Batch file that tests all mapped drives for disconnected ones, then attempts to reconnect, sometimes causing a user input in the cmd window to interrupt workflow (We have two security levels each with their own login credentials, and several of us have mapped network drives using each of the two creds, so some disconnected drives will require manual entry of username and password when the /USER:%username% %password%
parameters don't work, which I just can't seem to avoid. Neither server nor network location for NET USE
are viable tests for which security level, as their labeled after the project itself rather than the security level needed, and so my only remedy here would be to suppress the asking for user input).
Multiple batch files, one for each drive, requiring users to manually copy and alter batch files for their own needs (only one drive is universally used for each project we're on, and even then some people are one different projects), then updating the task scheduler to run each of their created files (not at all desirable, and as far as I'm concerned, unacceptable). If nothing else can be modified or work without interference, I can just using this to run on our company's default project drive letter, and let people worry about reconnecting the others as needed.
I have a task scheduled for any time our VPN client reports a connection, which due to our home networks and/or the connection between us and the VPN servers, could occur multiple times a day (I've had up to 4 or 5 "connection" events trigger my task after the initial login, though I only have to explicitly login the one time), which can cause further interruptions in workflow beyond just the initial VPN login run. I'm willing to accept any solution that uses NET USE
as long as I can suppress the request for user input if the Windows login password doesn't work, or a shortcut if I can prevent the opening of a file explorer window. Alternative solutions are preferred, but I understand that may not be possible.
I have tested using DIR //server/foo
, but it timed out for the same reasons that file explorer doesn't display the network drive as "connected" after VPN login is successful.
I've also had mixed results with setting the task scheduler to run my program off of a network connection as opposed to the "connect" event from our VPN client, mostly in that it didn't run reliably, if at all, as I needed to wait until I was connected through the VPN, not just standard internet connection through an ethernet cable. For this, I tried using both methods here, but none of the networks that are available after VPN login seemed to trigger the task properly, even though manually triggering the even through Task Scheduler showed the action would run fine. As such, I'm considering this as a failure, but can revisit if no more streamlined solutions are available or I can get a guarantee this method won't trigger as often (preferably only once per login) as watching the VPN client for its connection event.
At this point, I'm stuck with two solutions that have a high potential to interrupt workflow and annoy the user too greatly for me to want to send out as a final solution (a for loop on NET USE
where drive is disconnected and a batch file to open a shortcut that opens a window front and center), and another solution that I consider to limited in scope and as a last resort. I'll make due if there's not a better way to handle either of the first two, but in the mean time, I would greatly appreciate any help/advice!
Edit:
On a side note, I do expect to have the cmd window pop-up briefly, then close automatically once the operations are done (like it would with the shortcut solution), so some amount of workflow interruption will likely be unavoidable. What I'm considering unacceptable is that I can't minimize it and prevent the user form having to interact with it directly or indirectly to get the cmd or resulting window to close after it takes the active window status from whatever program user was previously in.
Edit 2:
I've posted this query elsewhere with this additional recap to help narrow my request: As a recap, I'm looking for a solution for refreshing network drive connections that do no rely on Credential Manager, will not require user input if network drive credentials differ from windows login credentials, and will not pop-up a window that requires user to close manually. Brief workflow interruptions resulting from cmd or child-process windows popping up before closing automatically are acceptable, with a preference towards one of the two solution avenues I already have running. Thanks again for any input you may have!
In lack of a better answer that is viable for our setup (will definitely remember Ben's answer for later, in case I'm able to use it for the lower security profiles), I've decided to go with a more limited scope for my batch file, since I have yet to find any info that will allow me to suppress a file explorer window or request for user input from the cmd window (for password) when attempting to refresh connection to all saved network drives.
Since the one drive that absolutely must be reconnected is, by our guidelines, universally assigned to the same letter (mapping changes depending on the primary project we're on), I've opted for just refreshing this drive as the credentials for this drive will always match the Windows login credentials, and thus won't request user for input if a password is wrong.
I will keep tabs on this question, so that if someone else comes along and has a better solution, I will definitely swap the selected answer to them.