Sign in with
Sign up | Sign in
Your question
Solved

Batch file net use

Last response: in Windows XP
Share
December 17, 2013 11:46:34 PM

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.

More about : batch file net

a b \ Driver
December 17, 2013 11:51:27 PM

Add the following line before the net use commands:
ping 192.168.0.10

The ping command won't return until the network interface is ready.
m
0
l
December 18, 2013 3:04:32 AM

VincentP said:
Add the following line before the net use commands:
ping 192.168.0.10

The ping command won't return until the network interface is ready.



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

m
0
l
Related resources

Best solution

a b \ Driver
December 18, 2013 3:11:38 AM

Usernameis said:
VincentP said:
Add the following line before the net use commands:
ping 192.168.0.10

The ping command won't return until the network interface is ready.



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.

Share
December 18, 2013 5:15:27 AM

VincentP said:
Usernameis said:
VincentP said:
Add the following line before the net use commands:
ping 192.168.0.10

The ping command won't return until the network interface is ready.



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.



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.
m
0
l
December 18, 2013 10:48:38 PM

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.

m
0
l
!