Jump to content

Script to modify Local Area Connection (HELP)


Tw_ix

Recommended Posts

I want to do the following for a Local Area Connection (under Windows XP):

- Modify the name of the connection (rename Local Area Connection to Corporate Network

- Enable the option ShowIcon (HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\{GUID of Adapter}\Connection\ShowIcon) ???

- Modify DNS Search List (HKLM\System\CurrentControlSet\Services\TCPIP\Parameters\SearchList) ???

- Enable NetBIOS (HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters\Interfaces\Tcp_{GUID of Adapter}\NetbiosOptions) ???

The problem is that on the machine I want to do this there are several connections (nic, wireless, vpn) and I don't know how to find the correct entries in the registries. The connection related ones must only by applied on the nic connection (not on the other two).

My idea was to use the IP address. The script I want to use will run while the nic is connected to our LAN. So I know a part of the IP range (first to octects).

I would like to do this via VBS. After google-ling a bit a round I create the following:

Const cIPOctet_1="192"

Const cIPOctet_2="168"

Const cConnectionName="Corporate Network"

Const NETWORK_CONNECTIONS = &H31&

Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

Set colNicConfigs = oWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

Set oShell = CreateObject("Shell.Application")

Set oFolder = oShell.Namespace(NETWORK_CONNECTIONS)

For Each oNicCfg In colNicConfigs

Set oNic = oWMIService.Get("Win32_NetworkAdapter.DeviceID=" & oNicCfg.Index)

For Each vIPAddress In oNicCfg.IPAddress

aOctets = Split(vIPAddress, ".")

If aOctets(0)=cIPOctet_1 And aOctets(1)=cIPOctet_2 Then vConnectionToRename=oNic.NetConnectionID

Next

Next

If vConnectionToRename <> "" and vConnectionToRename <> cConnectionName Then

Set colItems = oFolder.Items

For Each oItem in colItems

If oItem.Name = vConnectionToRename Then oItem.Name = cConnectionName

Next

End If

Set oWMIService = Nothing

Set colNicConfigs = Nothing

Set oShell = Nothing

Set oFolder = Nothing

The first part of the scripts finds the current name of the connection via the two first octets of the IP. Once the connection name is found the second part of the script loops until the name found before is detected and then renames it to the new name. This works!

But I now want to modify

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\{GUID of Adapter}\Connection\ShowIcon

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters\Interfaces\Tcp_{GUID of Adapter}\NetbiosOptions

But how can I detect this {GUID of Adapter} ??? I have the IP address of the connection and the connection name. Is there a way to query via VBS to find this GUID?

Can any one help? I have soon a major roll-out and need this script!

Many many thanks!

:blushing:

Take care,

Twixy

Link to comment
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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...