SGCAdmin
asked on
Net Use Command, Is there anyway to have it timeout and Go To the next line in Batch file
We are using a batch file to connect to our Broadband Wireless Card and then our VPN. After that is done, we have some if statements that state if it connects to the server, then do this, otherwise, GO TO end. The problem we are facing is that when it is connected to the internet, and not the VPN, it will try to connect forever to the folder using the net use command. We would like it to time out after a certain point so it moves on in the batch file. Is this possible?
Thanks!
Thanks!
Have you considered calling a separate batch file with the Start command, then add a 'wait' in your primary, and after x seconds test for an existing file on the VPN side to see if you connected. You could also have the primary kill the called batch if the connection test failed, on you way to the end.
ASKER
I would prefer only to have one batch file to simplify it. How would I create something that would say "if connection fails, do this"
Here is a snipet of the batch file:
REM Delete existing network drives
NET USE G: /DELETE >nul
REM Map Drive to Galileo Server
NET USE G: \\Servername\Folder <--------- At this point, it will sit forever.
ECHO Your G: Drive has been mapped
REM Run Anti-Virus Setup File
cALL G:\Progra~1\AUTHEN~1\ANTIV I~2\cuagen t.exe
IF EXIST G:\*.* GOTO END
pause
Here is a snipet of the batch file:
REM Delete existing network drives
NET USE G: /DELETE >nul
REM Map Drive to Galileo Server
NET USE G: \\Servername\Folder <--------- At this point, it will sit forever.
ECHO Your G: Drive has been mapped
REM Run Anti-Virus Setup File
cALL G:\Progra~1\AUTHEN~1\ANTIV
IF EXIST G:\*.* GOTO END
pause
That's the crux, since this cmd is going to sit in lala land waiting, as you have found out, the only way to maintain control is to branch off to another and then check to see if it is successful.
REM Map Drive to xxx
Start mapper.cmd (contains your NET USE G: \\Server...)
TIMEOUT 20 (number of seconds to let mapper.cmd complete or not)
IF NOT EXIST G:\*.* GOTO FAILURE
GOTO END
:FAILURE
TASKKILL /F /IM CMD.EXE (I'm assuming you would have no other cmd's running right now)
:END
Taskkill will kill both cmd's thereby accomplishing the same as ending the primary.
REM Map Drive to xxx
Start mapper.cmd (contains your NET USE G: \\Server...)
TIMEOUT 20 (number of seconds to let mapper.cmd complete or not)
IF NOT EXIST G:\*.* GOTO FAILURE
GOTO END
:FAILURE
TASKKILL /F /IM CMD.EXE (I'm assuming you would have no other cmd's running right now)
:END
Taskkill will kill both cmd's thereby accomplishing the same as ending the primary.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked perfectly, thanks!!
ASKER
Awesome answer, the ping and error level 1 line did it perfectly and I could leave it all in one batch file.
Thanks everyone!!
Thanks everyone!!