[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

batch script to detect type of network connection

Posted on 2012-04-03
7
Medium Priority
?
1,048 Views
Last Modified: 2012-04-17
This may sound a bit ambitious, but I would like a windows batch script that detects the type of network connection being used for the active internet connection.  It does not have to be 100% accurate, and any improvising is welcome.  It will be part of a gaming script, which will apply specific settings recommended by that game.  

Here is the idea...

if exist [56k modem detect script] goto 56k
if exist [wireless detect script] goto wifi
if exist [ethernet detect script] goto ether

:56k
echo. modifying for slow settings
goto next

:wifi
echo. modifying for strong but unstable settings
goto next

:ether
echo. modifying for fast settings
goto next

Open in new window

0
Comment
Question by:icecom4
[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
  • 3
7 Comments
 
LVL 57

Expert Comment

by:Bill Prew
ID: 37809235
You might be able to work something up for this, but it's going to be fairly tricky I think.  There are a number of commands line WMIC or NET etc that can expose some of the network adapter information, but determining if they are modems or wifi or enet will be tricky since you will likely have to interpret a vendor description of the device to decide that, and that will be hard to generalize and make foolproof.

Have you thought about asking the user a question in the BAT file instead, and just let them tell you what they have and then using that to drive your logic?

~bp
0
 

Author Comment

by:icecom4
ID: 37809472
Well, I am trying to make this a one click automated install.  It's pretty nice so far (thanks to you and others), and uses the zetprogressbar as a gui, the batch runs silent.  So I don't want to stop and ask any questions with a batch prompt.  

However, I have flirted with the possibility of adding some install flags to do a few optional tasks.  I just don't know how do that, and even if I did, to pass this from the installer package (winrar) to batch might make it more complicated.  

At this point, I am just working on a little cool factor for this installer.  

by the way, I may be looking to find an expert to look over the entire installer for mistakes, or things that might be hap-hazard.  know of anyone?
0
 
LVL 29

Expert Comment

by:matrixnz
ID: 37809916
You could use AutoIt and replace the batch altogether, below is a script I've used previously, I didn't write it but it worked well to tell us what type the connection was:

Global Const $INTERNET_CONNECTION_MODEM = 0x1
Global Const $INTERNET_CONNECTION_LAN = 0x2
Global Const $INTERNET_CONNECTION_PROXY = 0x4
Global Const $INTERNET_CONNECTION_MODEM_BUSY = 0x8
Global Const $INTERNET_RAS_INSTALLED = 0x10
Global Const $INTERNET_CONNECTION_OFFLINE = 0x20
Global Const $INTERNET_CONNECTION_CONFIGURED = 0x40

Dim $State, $val

$InetStruct = DllStructCreate("int")

$aRet = DllCall("wininet.dll", "int", "InternetGetConnectedState", "ptr", DllStructGetPtr($InetStruct), "int", 0)

ConsoleWrite("!> " & $aRet[0] & @LF)

$val = DllStructGetData($InetStruct, 1)

If BitAND($val, $INTERNET_CONNECTION_MODEM) Then $State &= "Modem connection" & @LF
If BitAND($val, $INTERNET_CONNECTION_LAN) Then $State &= "LAN connection" & @LF
If BitAND($val, $INTERNET_CONNECTION_PROXY) Then $State &= "Proxy connection" & @LF
If BitAND($val, $INTERNET_CONNECTION_MODEM_BUSY) Then $State &= "Modem bussy" & @LF
If BitAND($val, $INTERNET_RAS_INSTALLED) Then $State &= "RAS installed" & @LF
If BitAND($val, $INTERNET_CONNECTION_OFFLINE) Then $State &= "Offline connection" & @LF
If BitAND($val, $INTERNET_CONNECTION_CONFIGURED) Then $State &= "Connection configured"

MsgBox(0, "Connection", $State)

Open in new window

0
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!

 
LVL 57

Expert Comment

by:Bill Prew
ID: 37810933
Do you know if the computers running the BAT script will have WMIC installed on them?  We might be able to use that to find the active adapter, and then get it's speed.  I suspect that could be used to drive the decision you are trying to make.

~bp
0
 

Author Comment

by:icecom4
ID: 37811978
@bill

I am targeting windows XP sp 2 and higher.  I don't know if that answers your question.
0
 
LVL 57

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 37814797
Save this as a BAT file and give it a try on several computers.  It should display the name of the adapter that is active, and it's speed.  You may be able to do something like this and then use the speed to determine what capability to install or configure the game for.
@echo off
for /F "tokens=1* delims==" %%A in ('wmic /NameSpace:\\root\CIMV2 Path Win32_NetworkAdapter Where "(NetConnectionStatus='2' And AdapterTypeId='0' And PhysicalAdapter='TRUE')" Get Name /Format:LIST ^| find "="') do (
  for /F "tokens=*" %%C in ("%%~B") do (
    for /F "tokens=1* delims==" %%D in ('wmic /NameSpace:\\root\WMI Path MSNdis_LinkSpeed Where "InstanceName='%%~C'" Get NdisLinkSpeed /Format:LIST 2^>NUL ^| FIND "="') do (
      for /F "tokens=*" %%F in ("%%~E") do (
        echo %%~C,%%~F
      )
    )
  )
)

Open in new window

~bp
0
 

Author Comment

by:icecom4
ID: 37840332
@ Bill
thanks, and sorry for late reply.  I will look at this tonight.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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 …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

656 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