RSS

Windows networking script: Set show icon for all NICs

29 Jun

In the Internet, there is a number of examples of how to set an individual NIC to show icon in notification area, but you cannot find one if you want to set ALL the NICs by default. This is a required for my work and, hence, modified some of the scripts on the net and using WMI registry class to do the task.

You can download the VBS (please rename doc to vbs) script here

ShowIcon VBS Script

The WriteToLog() is my own function (show you some other days), you can replace it with WScript.echo.

Also note, I stopped indent after some levels so that it does not wrap around too much

‘==========================================
Sub SetShowIconValue
‘==========================================

Const HKLM = &H80000002

Dim ServerName
Dim objReg

Dim CtrlNetworkKeyPath
Dim arrAdapterGUIDs, AdapterGUID
Dim AdapterGUIDConnKeyPath
Dim AdapterNameValue
Dim AdapterNameStringValue
Dim ShowIconDWORDValue

ServerName = “.”

‘Don’t want any errors here to kill the program
On error resume next

Set objReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & _
ServerName & “\root\default:StdRegProv”)

‘This path is fixed in Windows

CtrlNetworkKeyPath = “SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}”

‘grab all the subkeys, i.e. the Adapter GUIDs

objReg.EnumKey HKLM, CtrlNetworkKeyPath, arrAdapterGUIDs

for each AdapterGUID in arrAdapterGUIDs

if InStr(AdapterGUID, “{“) > 0 then ‘look for keys that looks like a GUID

AdapterGUIDConnKeyPath = CtrlNetworkKeyPath & “\” & AdapterGUID & “\Connection”

AdapterNameStringValue = “”

objReg.GetStringValue

HKLM,AdapterGUIDConnKeyPath,”Name”,AdapterNameStringValue

if AdapterNameStringValue <> “” then

WriteToLog “Looking at registry path: ” & AdapterGUIDConnKeyPath
WriteToLog “Network Name: ” & AdapterNameStringValue

‘Just set all NICs regardless of their status, no harm done

objReg.SetDWORDValue HKLM,AdapterGUIDConnKeyPath,”ShowIcon”,1

if Err.Number = 0 then
WriteToLog “Show Icon value is set to: 1”

else
WriteToLog “Error ” & CStr(Err.Number) & ” while trying to check ShowIcon value, ” & Err.Description
end if

else

WriteToLog “Cannot get name for network adapter GUID:” & AdapterGUIDConnKeyPath

end if

end if

next

On error goto 0

End Sub

Advertisements
 
9 Comments

Posted by on June 29, 2007 in Scripts, VBScripts

 

Tags: ,

9 responses to “Windows networking script: Set show icon for all NICs

  1. rothgar

    August 16, 2007 at 5:58 pm

    The code looks great but I am confused on how to run it?

    It isn’t a reg file…
    not a batch script…
    not a Visual basic script (I could be wrong though)
    How do you actually perform this tweak? It would be A great tool for my work also (as we usually set these options by hand)

     
  2. saltwetfish

    August 17, 2007 at 4:34 am

    rothgar,

    This is a VBScript function. You need to rip it out and save it to a notepad with .vbs extension. As I mentioned also, please replace all the WriteToLog functions with WScript.echo, its my own private function (too lazy to remove, sorry).

    You can create a VBS script and run it interactively as this must be runned locally, the other way is to push out the script and schedule jobs to run it locally.

     
  3. rothgar

    August 29, 2007 at 5:04 am

    Thanks for the tip. I went ahead and replaced all of the WriteToLog functions and even all the quotes (they didn’t copy and paste correctly). and now I seem to get a error on Line 37 Char 92
    AdapterGUIDConnKeyPath = CtrlNetworkKeyPath & “\” & AdapterGUID & “\Connection”AdapterNameStringValue = “”

    It is right after the “\Connection”
    I am not familiar with the AdapterNameStringValue so I wasn’t sure if there was a mistake or if it should be something else.
    Thanks again for your help.

     
  4. saltwetfish

    August 29, 2007 at 10:33 am

    Hi Rothgar,

    Sorry about that, the formatting was messed up. Anyway, I have uploaded the VBS file and provided a link at the top of this updated posting. Its saved as DOC because wp only allows me to upload docs, please rename the extension to VBS.

     
  5. rothgar

    August 29, 2007 at 5:20 pm

    Thanks for the link. I was able to download it and run it on a XP pro machine without any errors. Only problem I found was the network icons don’t show up when connected. I checked in the network properties and the check box is also not checked to show the icon. I ran the script as administrator and I tried restarting the machine and running the script again with the same results.
    Thanks again for all your help so far. If you have anything you want me to try or suggestions on how to run it with debugging feel free to email me or I will check back here on your website.

     
  6. saltwetfish

    September 5, 2007 at 1:53 am

    Hi Rothgar,

    Sent you a private email, did not get your reply. Anyway, send me the logged output when you run the script and let me have a look.

     
  7. Me

    December 19, 2007 at 12:05 am

    Doesn’t appear to work… too bad.

     
  8. saltwetfish

    December 19, 2007 at 2:27 am

    Hi Me…

    Please let me know what errors you encountered and how you executed the script. Can’t help you much with that one-liner

     
  9. Eve

    February 14, 2008 at 9:33 am

    Work Well, author have to publish vbs file with txt file extention because copy/paste request some comprehensive vbs understanding and/or vbs skills.

    the main issue is due to blog/html paging. the line “objReg.GetStringValue HKLM,AdapterGUIDConnKeyPath,”Name”,AdapterNameStringValue” should be in the same line and not on more …

    Thanks a lot.

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: