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,184 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 83

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to batch remove spreadsheet password 19 198
Carriage Return in Batch File 5 51
changing harddisk on computer in corporate 10 43
Alert on Server memory 2 19
Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
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…

786 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