Jump to content

Activate the Network Tray Icon


Recommended Posts

I've searched and read for hours to see if anyone posted a solution to this but didn't find any, so here is a VBscript routine I wrote a while back to do the trick. I made it into a selfcontained subroutine so you can just plop it into an existing script if you like.

This bugger drove me nuts for a while and in fact was one of the primary reasons I took up VBscript several years ago. The connection state is under a key where part of the name contains the GUID for your NIC. Thus it's different for every computer. If you have a multihomed machine, you'll need to do some tweaking to enable the tray icon for both NICs.

'**********************************************************************

'** Subroutine; Show the tray icon for the network connection        **

'**********************************************************************

Sub NetTrayIcon

Dim strComputer, objReg, strKeyPath, strShowIcon, dwShowIcon, arrSubKeys, SubKey, FullKey

Dim arrEntryNames, arrValueTypes, i, strValue

strComputer = "."

Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}"

strShowIcon = "ShowIcon"

dwShowIcon = 1

objReg.EnumKey HKLM, strKeyPath, arrSubKeys

For Each SubKey In arrSubKeys

  If SubKey <> "Descriptions" Then

FullKey = strKeyPath & "\" & SubKey & "\Connection\"

      objReg.EnumValues HKLM, FullKey, arrEntryNames, arrValueTypes

      For i=0 To UBound(arrEntryNames)

    Select Case arrValueTypes(i)       

    Case REG_SZ           

        objReg.GetStringValue HKLM, FullKey, arrEntryNames(i),strValue

        If strValue = "Local Area Connection" Then

            objReg.SetDWORDValue HKLM, FullKey, strShowIcon, dwShowIcon

        End If

        End Select

    Next

  End If

Next

End Sub

I'm noticing in preview mode that this does not look nearly as readable as in PrimalScript, but it's really not too bad in a proper editor. I just thought that I'd throw this next piece in since it's sort of topic related. A VBscript line to change the name of your network connection.
ws.Run "netsh interface set interface name = ""Local Area Connection"" newname = ""APD Network""",0, True
Link to comment
Share on other sites


You can also use GreenMachines awesome batch file. It's amazingly tight for a batch file. Nice work on the VBscript too.

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

FOR /F "TOKENS=1 DELIMS= " %%A IN ('REG QUERY HKLM\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}') DO (

SET TEMP1=%%A
SET TEMP2=!TEMP1:~99,38!
SET TEMP3=!TEMP2:~-1!

IF "!TEMP3!"=="}" (

IF NOT "!TEMP2!"=="{4D36E972-E325-11CE-BFC1-08002BE10318}" (

 SET REGSTR1=HKLM\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\!TEMP2!\Connection
 SET REGSTR2=HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\!TEMP2!

 REG ADD !REGSTR1! /v ShowIcon /t REG_DWORD /d 1 /f
 REG ADD !REGSTR2! /v IPAutoconfigurationEnabled /t REG_DWORD /d 0 /f

)

)

)

Very Nice.

Link to comment
Share on other sites

Why go through all this hassle when this option can be specified in the winnt.sif file?

[Homenet]

ShowTrayIcon = Yes

HomeNet ... Tried that in XP Pro or Windows 2000?

EDIT:: Also requires Internet Connection Sharing ... Oh Brother ...

ShowTrayIcon

Value: Yes | No

Default: Yes

Enables or disables the display of the ICS tray icon. This entry requires that EnableICS = Yes.

Link to comment
Share on other sites

:blushing: D'oh! Since I've never used ICS, and in fact disable it through group policy in most instances, I ASSumed that the homenet setting was to show the tray icon for ICS (is there one?).

I suppose the bright side, if there is one, is that I learned how to step through a key in order to make a change. Not sure if I'll ever need to again...

oh well..

Link to comment
Share on other sites

Whoa, hold the phone (I cant believe I actually wrote that...)

Those icons in the system tray for networks (I have LAN, and Wireless) are NOT shown by default in WinXP SP2?!?

And, if not, this simple code in winnt.sif will enable them (but NOT ICS?)

[Homenet]
EnableICS = No
ShowTrayIcon = Yes

[edit]

I know I removed the "Bridge = Adapter1,Adapter2" line, because I THINK it creates a bridge, correct? If so, and you DISABLED ICS, whats the point of the bridge?

Link to comment
Share on other sites

@GM

offtopic question ?

Can i add reg.exe version 2.0 from the Windows 2000 support tools to my CD source built with the last version of XPcreate using the new functionality ?

A User defined FILESCD folder may now be used in conjunction with the XPCREATE FILESCD directory.

My needs is to add some M$ files (reg.exe wntipcfg.exe msconfig.exe) to this folder and let them added in dosnet.inf file and compressed in the I386 folder) without using $oem$\$$\system32 method ?

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...