• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6369
  • Last Modified:

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!
1
SGCAdmin
Asked:
SGCAdmin
  • 3
  • 2
1 Solution
 
DenverRickCommented:
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.
0
 
SGCAdminAuthor Commented:
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\ANTIVI~2\cuagent.exe
IF EXIST G:\*.* GOTO END
pause
0
 
DenverRickCommented:
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.

0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
oBdACommented:
Just ping the server, and if it doesn't respond, ignore the mapping:

echo Testing server ...
ping ServerNameOrIP | find /i "TTL" >NUL
if errorlevel 1 goto SkipMapping
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\ANTIVI~2\cuagent.exe 
IF EXIST G:\*.* GOTO END
:SkipMapping
pause

Open in new window

0
 
SGCAdminAuthor Commented:
Worked perfectly, thanks!!
0
 
SGCAdminAuthor Commented:
Awesome answer, the ping and error level 1 line did it perfectly and I could leave it all in one batch file.

Thanks everyone!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now