Jump to content

Find a value in registry and change it


Octopuss

Recommended Posts

There is probably an easy way to do this, but I am not too educated on the command line subject, so if someone could help me out I'd really appreciate it.

I need to rename network adapter names on all the machines of our client from the default "Local area connection" to "LAN" for batch network settings change.

I figured this is stored in registry, and finding it is actually pretty simple: REG QUERY HKLM\SYSTEM\CurrentControlSet\control\network\ /s /e /f "Local area connection"

BUT how do I change it when I don't know where is it located in the first place? There are a few diferent machine types with different adapters, so obviously the registry location is slightly different.

Link to comment
Share on other sites


I figured this is stored in registry, and finding it is actually pretty simple: REG QUERY HKLM\SYSTEM\CurrentControlSet\control\network\ /s /e /f "Local area connection"

BUT how do I change it when I don't know where is it located in the first place? There are a few diferent machine types with different adapters, so obviously the registry location is slightly different.

I am not sure to understand the question.

With the above command line you are using a "custom" string which is valid only for English systems BTW, it is perfectly possible that you have some other string in there if you deal with an "international" environment.

Also, there may be more than one "Local area connection", like "Local are connection 2", etc.

If you are sure about current name and are on English systems you can use netsh, see:

http://www.pcreview.co.uk/forums/rename-network-connection-t2439607.html

http://www.pcreview.co.uk/forums/nic-enumeration-t3142792.html

I would rather use WMI (or WMIC) to get the info first, like:

wmic nic get netconnectionID

wmic path Win32_networkadapterconfiguration where "IPENABLED=TRUE" get  Caption,SettingID /format:csv

A VBS:

http://forums.techarena.in/operating-systems/1206981.htm

jaclaz

Link to comment
Share on other sites

Well the string is of course different for different system language, but that's not a problem at all, I do know what is it called in czech. It's just about changing it.

Also I am only interested in the exact string without any numbers as those other adapters are things like VPN connections etc. I only need to change the name of the physical adapter in the computer.

I will check the links you posted.

Link to comment
Share on other sites

I tried the vbs script and it does work... up to a point. It renames anything that is NOT the network adapter. lol. Like on my work pc I have a Cisco VPN connection, and that somehow gets chosen by the script. Pretty funny. I gotta find someone who is proficient in scripting.

Link to comment
Share on other sites

I tried the vbs script

Honestly, that looks like a rather poorly thought script. Quite the hack job! Lots of pointless registry parsing, only then to rely on command line tools to do the job.

The Shell.NameSpace Method lets you access special folders like "network connections" by their CSIDL (find the full list in ShlObj.h) or known folders starting with Vista (values in KnownFolders.h). Once you set your "source folder" to that, you only have to iterate through them and set their names very much like you would normally with the FileSystemObject:

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" Then
objItem.Name = "LAN"
End If
Next

Code shamelessly copied from the scripting guys blog from MS here (yes, I am lazy!) jscript would be just as easy, it's mostly just adding an enumerator instead of the "For Each"...

Or if you're into powershell at all, try this 2 liner:


$shell = New-Object -comObject Shell.Application
$shell.Namespace(0x31).Items() | where {$_.Name -eq "Local Area Connection"} | foreach {$_.Name = "LAN"}

It's that simple. Unless you somehow need to do more than blindly renaming it (Local Area Connection -> LAN) and need to choose the connection.

Link to comment
Share on other sites

Hey thanks! I will definitely try that as well. All I need to accomplish is really just dumb batch-rename. I only need to be absolutely sure to rename the physical adapter and nothing else. But since we also have a minority of foreign users, I might as well need universal solution that doesn't just look for one specific string, but rather somehow identifies the adapter.

Link to comment
Share on other sites

No, unfortunately that's out of question. It's not about being lazy, but I just cannot do that. Anything that has anything to do with coding (this is coding in a way) is simply beyong what I can understand.

Link to comment
Share on other sites

All I need to accomplish is really just dumb batch-rename. I only need to be absolutely sure to rename the physical adapter and nothing else.

So you just need to rename blindly, but just not blindly? The scripts posted earlier won't check or care if connections are of any kind, they'll just rename the one connection with a specific name to another.

If you want a script that will automatically figure out which connection you'd like to rename it's a bit trickier. Yes, you can look for physical adapters, or those with an IP address and such. But having more than one network card (especially if you include wifi) is quite common. No matter what you do it will sometimes rename them not quite like you'd want it do.

Link to comment
Share on other sites

No, unfortunately that's out of question. It's not about being lazy, but I just cannot do that. Anything that has anything to do with coding (this is coding in a way) is simply beyong what I can understand.

Well this is IMHO completely unlike "coding" it is really about scripting.

Can you TYPE?

Or are you also fingerless?

I would rather use WMI (or WMIC) to get the info first, like:

wmic nic get netconnectionID

wmic path Win32_networkadapterconfiguration where "IPENABLED=TRUE" get  Caption,SettingID /format:csv

Type (one at the time) the above lines (pressing ENTER after each one)

What do you see?

jaclaz

Link to comment
Share on other sites

There is no need to be rude jac, I really didn't like the fingerless remark.

In my case (one physical adapter and one VPN connection) it shows:

Local Area Connection

Local Area Connection #2

The other command says "Invalid XSL format (or) file name."

Link to comment
Share on other sites

There is no need to be rude jac, I really didn't like the fingerless remark.

Well, you stated it was NOT lazyness, I was simply trying to find a rational explanation and no, the "Anything that has anything to do with coding (this is coding in a way) is simply beyong what I can understand." is not valid. :ph34r:

The other command says "Invalid XSL format (or) file name."

You have probably a typo, then.

Try copy/paste.

Try the simpler:

wmic path Win32_networkadapterconfiguration

then:

wmic path Win32_networkadapterconfiguration where "IPENABLED=TRUE" get  Caption,SettingID

And finally again:

wmic path Win32_networkadapterconfiguration where "IPENABLED=TRUE" get  Caption,SettingID /format:csv

jaclaz

Link to comment
Share on other sites

I did exact copy/paste and got this error.

The first command spammed me with several pages worth of stuff :P

The middle one looks interesting:

C:\Program Files\Windows AIK\Tools\PETools>wmic path Win32_networkadapterconfiguration where "IPENABLED=TRUE" get  Caption,SettingID
Caption SettingID

[00000007] Intel(R) 82566DC-2 Gigabit Network Connection {BD03DA90-F89B-485B-B76F-719C563873EA}
[00000015] Cisco Systems VPN Adapter for 64-bit Windows {6349C85D-366F-4714-8507-A04A54AF002C}

Edited by TheWalrus
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...