Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

:failed
echo Failed to ping %1
exit /b 1

:ok 
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.