From: Andrew Morgan on
Hi all

Does anyone have a script to check the following reg key ...

HKLM\System\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002
BE10318}\<adapter GUID>\Connection

.... to see if there's a ShowIcon key and if it is to set it to 1, or if not
create it.

This is to enable the 'network status icon' which appears in the bottom
right of the screen in XP. A simple reg hack won't work for me as the LAN
card on each machine will have a unique GUID. I need a script which will
look at the correct key. The key will have a 'name' value of 'Local Area
Connection'.

There may be other keys under "{4D36E972-E325-11CE-BFC1-08002BE10318}", but
only one should have the 'name' value 'Local Area Connection'. Others may
have "Local Area Connection 2", "Bluetooth Connection" etc.

Does that make sense ??!

Any advice is appreciated.

Andy


From: Bj�rn Holmgren on
"Andrew Morgan" <no.spam(a)any.time> wrote in message
news:O#6j3TcDFHA.1396(a)tk2msftngp13.phx.gbl...
> Hi all
>
> Does anyone have a script to check the following reg key ...
>
>
HKLM\System\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002
> BE10318}\<adapter GUID>\Connection
>
> ... to see if there's a ShowIcon key and if it is to set it to 1, or if
not
> create it.
>
> This is to enable the 'network status icon' which appears in the bottom
> right of the screen in XP. A simple reg hack won't work for me as the LAN
> card on each machine will have a unique GUID. I need a script which will
> look at the correct key. The key will have a 'name' value of 'Local Area
> Connection'.
>
> There may be other keys under "{4D36E972-E325-11CE-BFC1-08002BE10318}",
but
> only one should have the 'name' value 'Local Area Connection'. Others may
> have "Local Area Connection 2", "Bluetooth Connection" etc.
>
> Does that make sense ??!
>


Makes perfect sense. How about this:

Const HKEY_LOCAL_MACHINE = &H80000002
Const Key =
"System\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10
318}"
Dim objReg, arrSubKeys, i, iResult, ConnectionName, iShowIcon
On Error Resume Next
Set objReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
objReg.EnumKey HKEY_LOCAL_MACHINE, Key, arrSubKeys
For i = 0 To UBound(arrSubKeys)
iResult = objReg.GetStringValue(HKEY_LOCAL_MACHINE, _
Key & "\" & arrSubKeys(i) & "\Connection", "Name", ConnectionName)
If (iResult = 0) And (ConnectionName = "Local Area Connection") Then
iShowIcon = 0
iResult = objReg.GetDWORDValue(HKEY_LOCAL_MACHINE, _
Key & "\" & arrSubKeys(i) & "\Connection", "ShowIcon",
iShowIcon)
If (iResult <> 0) Or (iShowIcon = 0) Then
objReg.SetDWORDValue HKEY_LOCAL_MACHINE, _
Key & "\" & arrSubKeys(i) & "\Connection", "ShowIcon", 1
End If
End If
Next


--
Bjýrn Holmgren



From: Torgeir Bakken (MVP) on
Andrew Morgan wrote:

> Hi all
>
> Does anyone have a script to check the following reg key ...
>
> HKLM\System\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002
> BE10318}\<adapter GUID>\Connection
>
> ... to see if there's a ShowIcon key and if it is to set it to 1, or if not
> create it.
>
> This is to enable the 'network status icon' which appears in the bottom
> right of the screen in XP. A simple reg hack won't work for me as the LAN
> card on each machine will have a unique GUID. I need a script which will
> look at the correct key. The key will have a 'name' value of 'Local Area
> Connection'.
Hi

The script below enables the network status icon for the connection
that is named is "Local Area Connection"

It finds the SettingID property in the WMI class
Win32_NetworkAdapterConfiguration and uses that to locate the correct
adapter.


'--------------------8<----------------------
' Script for enabling the network icon in the systray
'
' Can be used against a remote computer as well
' For Win2k and WinXP only!
' Author: Torgeir Bakken


sComputer = "." ' use "." for local computer

'Constants for WMI StdRegProv
Const HKCR = &H80000000
Const HKCU = &H80000001
Const HKLM = &H80000002

Const NetBase = "SYSTEM\CurrentControlSet\Control\Network\"

On Error Resume Next

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& sComputer & "\root\default:StdRegProv")

' Finding the right place in registry is not so easy
' You must find the SettingID for the correct network adapter

' Get adapter collection
Set oAdapters = GetObject("winmgmts:").ExecQuery( _
"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True")

' Get all subkeys under NetBase in an array
iRC = oReg.EnumKey(HKLM, NetBase, aRegKeys)

' Finding adapter with connection name "Local Area Connection"
If (Err.Number = 0) And (iRC = 0) Then
On Error Goto 0
bAdapterFound = False
For Each oAdapter In oAdapters
sSettingID = oAdapter.SettingID
' Loop through all registry keys
For i = 0 To Ubound(aRegKeys)
sKeyName = NetBase & aRegKeys(i) & "\" _
& sSettingID & "\Connection"
oReg.GetStringValue HKLM, sKeyName, "Name", sValue
If LCase(sValue) = "local area connection" Then
bAdapterFound = True
WScript.Echo "Updating this setting id: " & sSettingID
WScript.Echo "Registry path: " & sKeyName
' Now we can get to the network icon setting in registry
oReg.SetDWORDValue HKLM, sKeyName, "ShowIcon", 1
Exit For
End If
Next
If bAdapterFound Then
Exit For
End If
Next

WScript.Echo "Finished, you must log off and on to see the change"

Else
WScript.Echo "Error in WMI registry parsing!"
End If
'--------------------8<----------------------


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
From: Andrew Morgan on
Thanks Bjorn and Torgeir for your help.

I'll give them both a try.

Your help is very much appreciated.

Regards
Andrew

"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam(a)hydro.com> wrote in message
news:e%23MeDOeDFHA.3368(a)TK2MSFTNGP10.phx.gbl...
> Andrew Morgan wrote:
>
> > Hi all
> >
> > Does anyone have a script to check the following reg key ...
> >
> >
HKLM\System\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002
> > BE10318}\<adapter GUID>\Connection
> >
> > ... to see if there's a ShowIcon key and if it is to set it to 1, or if
not
> > create it.
> >
> > This is to enable the 'network status icon' which appears in the bottom
> > right of the screen in XP. A simple reg hack won't work for me as the
LAN
> > card on each machine will have a unique GUID. I need a script which
will
> > look at the correct key. The key will have a 'name' value of 'Local
Area
> > Connection'.
> Hi
>
> The script below enables the network status icon for the connection
> that is named is "Local Area Connection"
>
> It finds the SettingID property in the WMI class
> Win32_NetworkAdapterConfiguration and uses that to locate the correct
> adapter.
>
>
> '--------------------8<----------------------
> ' Script for enabling the network icon in the systray
> '
> ' Can be used against a remote computer as well
> ' For Win2k and WinXP only!
> ' Author: Torgeir Bakken
>
>
> sComputer = "." ' use "." for local computer
>
> 'Constants for WMI StdRegProv
> Const HKCR = &H80000000
> Const HKCU = &H80000001
> Const HKLM = &H80000002
>
> Const NetBase = "SYSTEM\CurrentControlSet\Control\Network\"
>
> On Error Resume Next
>
> Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
> & sComputer & "\root\default:StdRegProv")
>
> ' Finding the right place in registry is not so easy
> ' You must find the SettingID for the correct network adapter
>
> ' Get adapter collection
> Set oAdapters = GetObject("winmgmts:").ExecQuery( _
> "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True")
>
> ' Get all subkeys under NetBase in an array
> iRC = oReg.EnumKey(HKLM, NetBase, aRegKeys)
>
> ' Finding adapter with connection name "Local Area Connection"
> If (Err.Number = 0) And (iRC = 0) Then
> On Error Goto 0
> bAdapterFound = False
> For Each oAdapter In oAdapters
> sSettingID = oAdapter.SettingID
> ' Loop through all registry keys
> For i = 0 To Ubound(aRegKeys)
> sKeyName = NetBase & aRegKeys(i) & "\" _
> & sSettingID & "\Connection"
> oReg.GetStringValue HKLM, sKeyName, "Name", sValue
> If LCase(sValue) = "local area connection" Then
> bAdapterFound = True
> WScript.Echo "Updating this setting id: " & sSettingID
> WScript.Echo "Registry path: " & sKeyName
> ' Now we can get to the network icon setting in registry
> oReg.SetDWORDValue HKLM, sKeyName, "ShowIcon", 1
> Exit For
> End If
> Next
> If bAdapterFound Then
> Exit For
> End If
> Next
>
> WScript.Echo "Finished, you must log off and on to see the change"
>
> Else
> WScript.Echo "Error in WMI registry parsing!"
> End If
> '--------------------8<----------------------
>
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/scriptcenter/default.mspx