?
Solved

Net Use Command, Is there anyway to have it timeout and Go To the next line in Batch file

Posted on 2008-06-26
6
Medium Priority
?
5,903 Views
1 Endorsement
Last Modified: 2010-04-21
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
Comment
Question by:SGCAdmin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:DenverRick
ID: 21875459
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
 
LVL 1

Author Comment

by:SGCAdmin
ID: 21875618
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
 
LVL 8

Expert Comment

by:DenverRick
ID: 21875741
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
Industry Leaders: 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!

 
LVL 85

Accepted Solution

by:
oBdA earned 1000 total points
ID: 21875794
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
 
LVL 1

Author Closing Comment

by:SGCAdmin
ID: 31470999
Worked perfectly, thanks!!
0
 
LVL 1

Author Comment

by:SGCAdmin
ID: 21876221
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick step-by-step overview of installing and configuring Carbonite Server Backup.
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question