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
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
5,326 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
  • 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 84

Accepted Solution

by:
oBdA earned 250 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 Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

790 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