What is the best method for creating a batch file (.bat) that will automatically map network drives after a internet connection has been established. The batch file will be remain in the windows start up folder and will only map the network drives if they are not already mapped. I have tried the following:
:Start
ping -n 1 www.google.com
If %errorlevel% == 0 Goto :Start
If %errorlevel% == 1 Goto :Connected
:Connected
Net Use F:\\ Server\Folder /Persistent:No
The ping reply is so fast that the Net use command doesn't map the drive even though the path is correct and will work if I manually enter the net use and path in the CMD window. I need for it to wait after the ping reply and then map the network drives and also for it to only map the network drives if they are not already mapped. I realize what I have tried doesn't address the "only map the network drives if they are not already mapped". I have done some extensive searching and I cannot find the answer to these issues. Would appreciate step by step and easy to follow instructions for resolving this.
Thank you very much.
Maybe additional "timeout" can help?
updated
I use windows vpn client. To check available connection i make script like this and wait 30 second before check by ping. And i ping my server which available only under vpn.