Batch Scripting - Waiting for the network to be established


I have logon.bat script that runs each time a user logs into their workstation of an Active Directory domain.

This script maps some network drives with commands like this:

net use x: \\\share1
net use y: \\\share2
net use z: \\\share3

However, for some workstations, this script is running before the the workstation itself has fully established its own LAN connection. The user then goes to Start Menu > Computer, and see red X's for each mapped drive. By this time, the network is established, so if they click on the red X, it goes away. Still, I would like the logon.bat script to verify the network is established before running the net-use commands.

I've seen solutions for this that require settings to be changed on group policy or require changes to settings on the culprit-workstation. However, I'm interested in a solution that solves this exclusively within my current batch script (without requiring any additional script-dependencies outside of that script).

I've seen other scripting solutions that simply put a timeout (or sleep) into the batch script so that it waits an arbitrary amount of time before running the net use commands. These solutions provide wait-constants that either "map the drives a little too much later than they could've been mapped" or "still risk running the net-use commands earlier than network is established".

Instead, I'd like a script that would check every second to see if the network has been established, and then (upon success) proceed to run the "net use" commands mentioned previously.

How do you achieve this in a Windows batch script?

Simple check. Doesn't exit after automatically after a duration. Worked for what I needed.