Solved

Batch file net use

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.
5 answers Last reply Best Answer
More about batch file net
  1. 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.
  2. 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.
  3. Best answer
    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.
  4. 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.
  5. 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.
Ask a new question

Read More

Drivers Command Prompt Windows XP