How do I programatically change a device's FriendlyName

Using Windows 7:

Our product has 2 identical wireles cards. I have figured out how to programatically tell the difference between the 2 cards so I can know which is which. I’ve also figured out how to programatically write a “Friendly” name for each wireless card to the registry. (HLKM/SYSTEM/CurrentControlSet/Control/Network/{4D36E972…}/{DEVGUID}/Connection/Name)

Let me inject here that it’s important to know which card is which because one can be connected to an external directional antenna that can be used to track down rogues.

The problem is that the WlanAutoConfig service does not see the name change and continues to use the old names. If I rename the devices with Explorer, then WlanAutoConfig sees the change and uses the new names. Rebooting or restarting the service does not recognize the new name.

Can I programatically change the name in the same way that explorer does? And if so, how?

Or is there some API that I need to call with the new name to force it into auto config?

Clay

INetCfgComponent::SetDisplayName ?

http://msdn.microsoft.com/en-us/library/ff547902(VS.85).aspx

some command in netsh might work too…

d

The easiest way is to execute
netsh.exe interface set interface name=“Local Area Connection 2” newname=“My cool adapter”

I don’t recall there being a proper API for this – I think the idea was that the ifAlias belongs more to the end-user. The API that Doron mentioned, INetCfgComponent::SetDisplayName, sets the ifDescr. That’s actually the ideal place for you to advertise your hardware, per RFC 2863. (I’m not saying you *can’t* set the ifAlias, it’s just a FYI.)

And as always, please don’t rummage through the registry and set random keys.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@email.com
Sent: Thursday, December 16, 2010 3:52 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] How do I programatically change a device’s FriendlyName

Using Windows 7:

Our product has 2 identical wireles cards. I have figured out how to programatically tell the difference between the 2 cards so I can know which is which. I’ve also figured out how to programatically write a “Friendly” name for each wireless card to the registry. (HLKM/SYSTEM/CurrentControlSet/Control/Network/{4D36E972…}/{DEVGUID}/Connection/Name)

Let me inject here that it’s important to know which card is which because one can be connected to an external directional antenna that can be used to track down rogues.

The problem is that the WlanAutoConfig service does not see the name change and continues to use the old names. If I rename the devices with Explorer, then WlanAutoConfig sees the change and uses the new names. Rebooting or restarting the service does not recognize the new name.

Can I programatically change the name in the same way that explorer does? And if so, how?

Or is there some API that I need to call with the new name to force it into auto config?

Clay


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

>“Friendly” name for each wireless card to the registry.

(HLKM/SYSTEM/CurrentControlSet/Control/Network/{4D36E972…}/{DEVGUID}/Connection/Name)

Try using INetCfg APIs instead of hacking the undocumented registry values.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

Use INetCfg API instead of using/hacking windows reg values.

HRESULT hr
INetCfgComponent pnccAdapter;
HKEY hPortKey;
//Get the pnccAdapter INetCfgComponent ptr and proceed
hr = pnccAdapter->OpenParamKey(&hPortKey);
if ( hr != S_OK )
{
return hr;//error
}
hr = pnccAdapter->SetDisplayName(L"MYNAME…");
if (S_OK != hr)
{
return hr;//error
}

Regards
Satheesh

On Thu, Dec 16, 2010 at 11:06 PM, Maxim S. Shatskih
wrote:

> >“Friendly” name for each wireless card to the registry.
>
> >(HLKM/SYSTEM/CurrentControlSet/Control/Network/{4D36E972…}/{DEVGUID}/Connection/Name)
>
> Try using INetCfg APIs instead of hacking the undocumented registry values.
>
> –
> Maxim S. Shatskih
> Windows DDK MVP
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

It turns out that my use of the term “FriendlyName” was not correct. In fact, I’m not trying to change the friendly name of the driver.

It seems that a device has at least 3 names (probably more).

  1. The name derived from the INF file. Maybe called the DeviceDescription
  2. The Friendly Name that can be displayed in place of #1. It is called FriendlyName or DisplayName
  3. Some as of yet unidentified (to me) name used by Explorer and Autoconfig

If you look at this screenshot, you will see that Explorer shows 2 names on my wireles card. The one at the bottom “TEST1” is the name that I set by using INetCfgComponent->SetDisplayName()
It can also be set using SetupDiSetDeviceRegistryProperty(… SPDRP_FRIENDLYNAME…)

The name at the top “Renamed Wireless” is set from Explorer/Rename.

http://vragor.smugmug.com/photos/1129640885_4fAax-O.jpg

As you can see in the next screen shot, Autoconfig does not use the FriendlyName. Instead it uses the same name as Explorer - “Renamed Wireless”

http://vragor.smugmug.com/photos/1129640891_coBaV-O.jpg

In the next shot you can see me renaming the wireless card with Explorer

http://vragor.smugmug.com/photos/1129640893_HqZuy-O.jpg

And you can see that new name is reflected in Autoconfig

http://vragor.smugmug.com/photos/1129640890_h8dae-O.jpg

As a little more example, you can see that Device Manager uses the Friendly Name when it displays the device.

http://vragor.smugmug.com/photos/1129640898_GgaMC-O.jpg

But the Network Sharing Center uses the same name as Explorer and Autoconfig.

http://vragor.smugmug.com/photos/1129640892_dt2ze-O.jpg

So my originally misworded question still remains. How can I programatically rename the device in such a way that it will be reflected in autoconfig?

Thanks
Clay

I thought I answered this question, but re-reading it, I guess I wasn’t terribly clear. Sorry.

A network interface has a few networking-specific properties, derived from RFC 2863. Of interest are ifAlias and ifDescr:

ifAlias: “Local Area Connection 2” – this is the user’s name for the interface. What you call Explorer/Rename.

ifDescr: “Intel(R) 82567LM Gigabit Network Adapter” – this is the vendor’s description of the hardware (or virtual miniport).

Also, the underlying hardware device has a couple PNP names (this is an NT kernel thing, not a networking-specific thing):

Device description: This comes from the INF.

Friendly name: This is initially snapshotted from the device description, but it can be renamed later. In particular, the networking setup engine keeps the ifDescr in synch with this name, so if you change the ifDescr, the PNP friendly name is changed too.

You want to modify the ifAlias. The way to do that is, as I mentioned before, with the “netcfg int set int” command. As you’ve noticed, what INetCfgComponent::SetFriendlyName calls the “Friendly name” does not modify the ifAlias – it actually modifies the ifDescr and PNP friendly name.

There is a rationale behind all this. If you look at the RFC, the idea is that users typically modify the ifAlias (which is why the shell makes it easy to rename that); while vendors get to billboard in ifDescr (which is why there’s a handy INetCfg API for setting that).

BTW, in case you’re curious, there’s also an ifName for a network interface, and it’s different from all of the above. (On Windows, it’s defined to be the NET_LUID.) I suppose someday I should bang out a blog post on all this.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@email.com
Sent: Friday, December 17, 2010 2:42 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] How do I programatically change a device’s FriendlyName

It turns out that my use of the term “FriendlyName” was not correct. In fact, I’m not trying to change the friendly name of the driver.

It seems that a device has at least 3 names (probably more).

  1. The name derived from the INF file. Maybe called the DeviceDescription
  2. The Friendly Name that can be displayed in place of #1. It is called FriendlyName or DisplayName
  3. Some as of yet unidentified (to me) name used by Explorer and Autoconfig

If you look at this screenshot, you will see that Explorer shows 2 names on my wireles card. The one at the bottom “TEST1” is the name that I set by using INetCfgComponent->SetDisplayName()
It can also be set using SetupDiSetDeviceRegistryProperty(… SPDRP_FRIENDLYNAME…)

The name at the top “Renamed Wireless” is set from Explorer/Rename.

http://vragor.smugmug.com/photos/1129640885_4fAax-O.jpg

As you can see in the next screen shot, Autoconfig does not use the FriendlyName. Instead it uses the same name as Explorer - “Renamed Wireless”

http://vragor.smugmug.com/photos/1129640891_coBaV-O.jpg

In the next shot you can see me renaming the wireless card with Explorer

http://vragor.smugmug.com/photos/1129640893_HqZuy-O.jpg

And you can see that new name is reflected in Autoconfig

http://vragor.smugmug.com/photos/1129640890_h8dae-O.jpg

As a little more example, you can see that Device Manager uses the Friendly Name when it displays the device.

http://vragor.smugmug.com/photos/1129640898_GgaMC-O.jpg

But the Network Sharing Center uses the same name as Explorer and Autoconfig.

http://vragor.smugmug.com/photos/1129640892_dt2ze-O.jpg

So my originally misworded question still remains. How can I programatically rename the device in such a way that it will be reflected in autoconfig?

Thanks
Clay


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Jeffrey,

I missed your post in the middle of all that other replies. Indeed it pointed exactly to what I was looking for. In your last post you accidently said “NETCFG” when you meant “NETSH”, but all your info was spot on and very helpful. Thanks.

My searching skills haven’t led me to find a good netsh document, so I had to piece together exactly how to use it from what you said and some other pages on the web.

Executing the console command:

c:\>netsh interface show interface

will give a list of all network adapters and their current state. Within that list will be the “Interface name” such as “Local Area Connection” or “Wireless Adapter”. Using the interface name, you can rename the device with a command like:

c:\>netsh interface set interface name=“Local Area Connection” newname=“Onboard Gig Nic”

Once the device is renamed, it will show up in the Autoconfig dialog boxes. You must have excallated rights to execute the rename command.

Thanks again
Clay