Batch file net use

Usernameis

Honorable
Nov 22, 2013
36
0
10,530
Hi.
Currently I am using this batch file command to auto-login to mapped network drivers. Issue is, what it runs earlier than network gets connection and eventually I need to run it manually.

net use x: \\192.168.0.10\data1 /user:XXX 123XXX
net use v: \\192.168.0.20\data2 /user:XXXX 321XXX


how to run it till will succeed.

 
Solution


20s is a long time.
How long before the network connection ready?
You can use "ping -n 10 192.168.0.10" to increase the ping to 10 requests, or vary this number as required.

Usernameis

Honorable
Nov 22, 2013
36
0
10,530



it doesn't work. Ping fails in about 20s and net use command fails. So needs to re-open batch file manually as always.

 


20s is a long time.
How long before the network connection ready?
You can use "ping -n 10 192.168.0.10" to increase the ping to 10 requests, or vary this number as required.

 
Solution

Usernameis

Honorable
Nov 22, 2013
36
0
10,530


Actually I was looking for a more sophisticated method with loops, errorlevel, set commands and so on (I was looking at google but couldn't modify it to work in my case).

Anyway, your multiple ping sorts this issue out. Thank you very much for a good idea.
 

Usernameis

Honorable
Nov 22, 2013
36
0
10,530
Finally found short, simple and very accurate solution below:

@echo off
echo connecting to network disks
:connection
net use x: \\192.168.0.10\data1 /user:XXX 123XXX
net use v: \\192.168.0.20\data2 /user:XXXX 321XXX
if errorlevel 1 goto connection
echo connection successful
goto end
:end


Anyway, all help received is appreciated.