Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using net use x: "\\DEVICE\SHARE" /persistent:no in a batch file to connect to shares at start up. However, sometimes if I am offline or if the server/device is offline the command will hang for a few minutes before failing. When I have the command running multiple times sequentially, this can take a long time. Is there a way to get computer to check that the remote device is available before trying to mount it?

share|improve this question
up vote 2 down vote accepted

Here's a workaround that could work in your case: try to ping the device before trying to net use its share.

You can do that easily enough in a .cmd script. Here's a short example check_if_pings.cmd that you could adapt:

@echo off

ping -n 1 -w 1000 %1 > NUL
if %ERRORLEVEL% NEQ 0 goto failed
goto ok

echo Failed to ping %1
exit /b 1

echo Ping %1 ok
exit /b 0

The -n parameter to ping specifies how many packets to send, and the -w how many milliseconds to wait for the reply to come. Adjust these to fit your needs.

share|improve this answer

You must log in to answer this question.