Jump to content
Sign in to follow this  
TheGreatandMightyMe

Searching the registry

Recommended Posts

TheGreatandMightyMe

I need to generate a list of all the available network connections on a given pc. This script needs to work on a variety of systems, but they all run xp so the registry would be the best constant, I think. I can get very close to the directory where the names are stored but the last two folders have different name depending on the machine. This is what I was trying.

$connections = RegRead("HKEY_LOCAL_MACHINE\system\controlset001\control\network\*\*\connections", "Name")

MsgBox(4096, "connections are:", $connections)

Note: This is just part of a test script. It is not the full thing because I'm not going to move forward till I figure out this part.

The problem is the any references don't seem to work. Is there a better way to do this.

Thanks in advance,

Me

Share this post


Link to post
Share on other sites
weaponx

When you say "network connections", what are you wanting to retrieve? Physical hardware? Protocols?

Regardless, the registry is probably the worst way to go about doing this.

Share this post


Link to post
Share on other sites
TheGreatandMightyMe

When you say "network connections", what are you wanting to retrieve? Physical hardware? Protocols?

Regardless, the registry is probably the worst way to go about doing this.

I need the names of the connections (ex: Local Area Connection or Local Area Connection 2 ). If the registry is the worst way to do this what would work better. I only say I think the registry is good because it is such a constant between systems.

Share this post


Link to post
Share on other sites
weaponx

Do you need to use the results in a script? If not you can do:

(From the command prompt)

netsh interface showinterface

If you need to use the results in a script I think WMI would be the next best thing.

Share this post


Link to post
Share on other sites
TheGreatandMightyMe

That command did not work for me (tried it manually). The results do need to go into a script. I found a command to export the entire directory from the registry and I know where in the text it lists the connection names. Right now I'm trying to find a way to make it pull out the names. I'm going to attach a copy of what the registry export looks like. The line I need to pull from is the line that says:

"Name"="Local Area Connection 2"

and

"Name"="Local Area Connection"

I need it to pull out

Local Area Connection 2

and

Local Area Connection

or whatever the name of the connection happens to be.

Thanks again for the help.

networkkeys.txt

Share this post


Link to post
Share on other sites
flyingboz

try from cmd...

NETSH INTERFACE SHOW INTERFACE

ignore Internal and Loopback

A second vote for Larry's approach.. It beats WMI from a performance / reliability standpoint hands down.

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites
TheGreatandMightyMe

A second vote for Larry's approach.. It beats WMI from a performance / reliability standpoint hands down.

Yes that does work. Now how can I take that data and use it inside a script.

Share this post


Link to post
Share on other sites
weaponx

Do you need to use the results in a script? If not you can do:

(From the command prompt)

netsh interface show interface

If you need to use the results in a script I think WMI would be the next best thing.

Ah crap I forgot a space in there.

Share this post


Link to post
Share on other sites
TheGreatandMightyMe

Ah crap I forgot a space in there.

Is there some way I can use that data in a script?

Share this post


Link to post
Share on other sites
weaponx

This is the best I could come up with:

#include 
#include 

$process = Run("netsh interface show interface", @ScriptDir, @SW_HIDE, $STDOUT_CHILD)

;Wait for netsh to complete before showing results
While ProcessExists ($process)
    Sleep(250)
Wend 

$line = StdoutRead($process)
$array = StringSplit ( StringStripWS(StringStripCR($line), 2), @LF)
_ArrayDisplay ($array)

Share this post


Link to post
Share on other sites
TheGreatandMightyMe

$STDOUT_CHILD = 2

ToolTip("working...")

$a = Run("netsh interface show interface","",@SW_HIDE,$STDOUT_CHILD)
$buffer = ""
While ProcessExists($a)
    $buffer &= StdoutRead($a)
    Sleep(1)
WEnd

ToolTip("")

MsgBox(4096,"",$buffer)
Thanks! This works perfectly. It returns exactly what I needed. You guys are awesome. You helped me really fast the first time I ever came on here. These are really good forums. I think I'll stick around.

Share this post


Link to post
Share on other sites
weaponx

Because I refuse to be outdone, this will split all the columns off into a multidimensional array:

#include <Array.au3>
#include <Constants.au3>

Dim $connections[1][3]
$process = Run("netsh interface show interface", @ScriptDir, @SW_HIDE, $STDOUT_CHILD)

;Wait for netsh to complete before showing results
While ProcessExists ($process)
    Sleep(250)
Wend

$line = StdoutRead($process)
$array = StringSplit ( StringStripWS(StringStripCR($line), 2), @LF)
_ArrayDisplay ($array)

$Y = 0
For $X = 4 to $array[0]
    If $Y > 0 Then
        Redim $connections[$Y + 1][3]
    EndIf
    $split = StringSplit(StringStripWS($array[$X], 4), " ") 
    ;Add State to array
    $connections[$Y][0] = $split[1]
    ;Add Type to array
    $connections[$Y][1] = $split[2]
    ;Add Interface
    $connections[$Y][2] = _ArrayToString ( $split, " ", 3)
    $Y += 1
Next

_ArrayDisplay ($connections)

Share this post


Link to post
Share on other sites
TheGreatandMightyMe

Because I refuse to be outdone, this will split all the columns off into a multidimensional array:

#include <Array.au3>
#include <Constants.au3>

Dim $connections[1][3]
$process = Run("netsh interface show interface", @ScriptDir, @SW_HIDE, $STDOUT_CHILD)

;Wait for netsh to complete before showing results
While ProcessExists ($process)
    Sleep(250)
Wend

$line = StdoutRead($process)
$array = StringSplit ( StringStripWS(StringStripCR($line), 2), @LF)
_ArrayDisplay ($array)

$Y = 0
For $X = 4 to $array[0]
    If $Y > 0 Then
        Redim $connections[$Y + 1][3]
    EndIf
    $split = StringSplit(StringStripWS($array[$X], 4), " ") 
    ;Add State to array
    $connections[$Y][0] = $split[1]
    ;Add Type to array
    $connections[$Y][1] = $split[2]
    ;Add Interface
    $connections[$Y][2] = _ArrayToString ( $split, " ", 3)
    $Y += 1
Next

_ArrayDisplay ($connections)
Wait a sec... Didn't larry's code already use an array. The diplay it gave looks like a multi dimensional array to me. I think I got lost some where.

EDIT: Now I see that larry's $buffer variable is not an array. Why did it display in a format other than a straight line?

Edited by TheGreatandMightyMe

Share this post


Link to post
Share on other sites
SmOke_N

Wait a sec... Didn't larry's code already use an array. The diplay it gave looks like a multi dimensional array to me. I think I got lost some where.

EDIT: Now I see that larry's $buffer variable is not an array. Why did it display in a format other than a straight line?

The stdout probably truncates at the null char and adds a CRLF (Never really stopped to think about it before).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×