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
4,978 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 82

Accepted Solution

by:
oBdA earned 250 total points
Comment Utility
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
Comment Utility
Worked perfectly, thanks!!
0
 
LVL 1

Author Comment

by:SGCAdmin
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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 …
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now