How Can I Rename a Local Area Connection?

How Can I Rename a Local Area Connection?

  • Comments 8
  • Likes
Hey, Scripting Guy! Question

Hey, Scripting Guy! How can I rename a local area connection?

-- AP

SpacerHey, Scripting Guy! AnswerScript Center

Hey, AP. You know, you hurt our feelings here: we Microsoft types spent a lot of time coming up with clever and catchy names like Local Area Connection, Local Area Connection 2, and Local Area Connection 3. And now you say you want to change those names? That hurts.

But you know what they say: the customer is always right. Give us a minute to dry our tears and then we’ll show you a script that changes the name of Local Area Connection 2 to Home Office Connection.

OK, we’re better now:

Const NETWORK_CONNECTIONS = &H31&

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(NETWORK_CONNECTIONS)

Set colItems = objFolder.Items
For Each objItem in colItems
    If objItem.Name = "Local Area Connection 2" Then
        objItem.Name = "Home Office Connection"
    End If
Next

You might not be aware of this, but network connections are actually housed in a Windows special folder. Of course, this particular folder is really special: instead of having a path like C:\Documents and Settings\kenmyer\My Documents it has a path like this:

::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{21EC2020-3AEA-1069-A2DD-08002B30309D
}\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}

Yikes! But that’s OK. You won’t have much success passing a folder path like that to the dir command, but you can use the Shell object to bind to the path, list all the items (that is, all the network connections) found in the folder, and rename any of those items. And that’s exactly what our script does.

We begin by defining a constant named NETWORK_CONNECTIONS and assigning it the value &H31&; we’ll use this constant to tell the Shell object which special folder we want to work with. We then create an instance of the Shell.Application object, then use the Namespace method to bind to the Network Connections folder. That’s what we do here:

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(NETWORK_CONNECTIONS)

After we bind to the Network Connections folder we can start doing something a bit more interesting. To begin with, we use the Items method to return a list of all the items found in the folder; because we’re dealing with the Network Connections folder that’s going to be a list of all the network connections on the computer. We then set up a For Each loop to iterate through the collection, checking to see if any of the connections have the Name Local Area Connection 2. If they do, we simply use the Shell object to change the Name to Home Office Connection. That’s what we do here:

For Each objItem in colItems
    If objItem.Name = "Local Area Connection 2" Then
        objItem.Name = "Home Office Connection"
    End If
Next

That’s all you have to do: Local Area Connection 2 will now be named Home Office Connection and all will be right with the world.

And before you ask, the answer is no: we will never change the name of the Scripting Guys. Ever.

Well, unless - taking a cue from major league sports - someone would be interesting in buying the naming rights to the Scripting Guys. The Fabrikam Scripting Guys? Contoso Corporation Presents the Scripting Guys? We’re open to offers….

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Anyway to do this in powershell?

  • What if there are 15 or 20 orphaned "Wireless Network Connection xx" entries in the registry? From driver re-installs, ect. How can I remove all orphaned entries via script, so I can change my "Wireless Network Connection xx" back to "Wireless Network Connection" (in win7)

    Sure I can do this manually via registry, but I would like some sort of automated cleanup for this sort of thing

  • Interfaces can also be renamed with the netsh command:  mikefrobbins.com/.../rename-a-network-interface-from-the-command-line

  • @Sean it is easy to do using the NETSH command.

    @JGreen1280 I would use NETSH instead of hacking the registry ... it would be safer.

    @Seth Fulton thanks for providing the link.

  • How can we delete the connection instead of renaming?

  • The renaming works, but I don't have control over which nic will be named "Local Area Connection"and which "Local Area Connection 2". When I deinstall the adapters and reboot they are sometimes reversed in the Network Connections window.

    Is it possible to identify and select them on another criterium? The PCI bus (physical location) seems a pretty obvious choise. Would that be possible and how?

  • netsh interface set interface name="Local Area Connection" nename="Home Office Connection"

  • How would you script what JGreen1280 mentioned in his comments? I need to script a way to remove all ophaned entries so when I install multiple new TAP-Win32 connections they start at "Local Area Connection #2" instead some obscure number depending on the registry. That way a simple rename command would work. The clients I will be sending this batch file out to will have no way of knowing the number of orphaned entries on their machine and I want the script to rename automatically. Any help? Thanks.