Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

Find a value in registry and change it


  • Please log in to reply
26 replies to this topic

#1
Octopuss

Octopuss

    I am the walrus

  • Member
  • PipPipPipPipPipPip
  • 1,127 posts
  • Joined 31-January 07
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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.




How to remove advertisement from MSFN

#2
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,655 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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....n-t2439607.html
http://www.pcreview....n-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.techar...ems/1206981.htm

jaclaz

#3
Octopuss

Octopuss

    I am the walrus

  • Member
  • PipPipPipPipPipPip
  • 1,127 posts
  • Joined 31-January 07
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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.



#4
Octopuss

Octopuss

    I am the walrus

  • Member
  • PipPipPipPipPipPip
  • 1,127 posts
  • Joined 31-January 07
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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.

#5
iamtheky

iamtheky

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 866 posts
  • Joined 11-November 08
wmic nic where netconnectionID="Local Area Connection" get name | find /V "Cisco"

Edited by iamtheky, 25 August 2011 - 04:00 PM.

iamtheKy

#6
CoffeeFiend

CoffeeFiend

    Coffee Aficionado

  • Super Moderator
  • 5,399 posts
  • Joined 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag

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.
Coffee: \ˈkȯ-fē, ˈkä-\. noun. Heaven in a cup. Life's only treasure. The meaning of life. Kaffee ist wunderbar. C8H10N4O2 FTW.

#7
Octopuss

Octopuss

    I am the walrus

  • Member
  • PipPipPipPipPipPip
  • 1,127 posts
  • Joined 31-January 07
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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.

#8
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,655 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

I gotta find someone who is proficient in scripting.


I don't want to seem more grumpy than usual :ph34r: , but I thought you were here to learn how to do that yourself. :unsure:

jaclaz

#9
Octopuss

Octopuss

    I am the walrus

  • Member
  • PipPipPipPipPipPip
  • 1,127 posts
  • Joined 31-January 07
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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.

#10
CoffeeFiend

CoffeeFiend

    Coffee Aficionado

  • Super Moderator
  • 5,399 posts
  • Joined 14-July 04
  • OS:Windows 7 x64
  • Country: Country Flag

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.
Coffee: \ˈkȯ-fē, ˈkä-\. noun. Heaven in a cup. Life's only treasure. The meaning of life. Kaffee ist wunderbar. C8H10N4O2 FTW.

#11
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,655 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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

#12
Octopuss

Octopuss

    I am the walrus

  • Member
  • PipPipPipPipPipPip
  • 1,127 posts
  • Joined 31-January 07
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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



#13
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,655 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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

#14
Octopuss

Octopuss

    I am the walrus

  • Member
  • PipPipPipPipPipPip
  • 1,127 posts
  • Joined 31-January 07
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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, 30 August 2011 - 02:39 AM.


#15
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,655 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
I see now :), you are running 7.

WMIC (at least on XP) allows for /format:csv .

It has changed on 7, (cannot say why):
http://xinn.org/misc-scripts/wmic.txt

Try:

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


jaclaz

#16
Octopuss

Octopuss

    I am the walrus

  • Member
  • PipPipPipPipPipPip
  • 1,127 posts
  • Joined 31-January 07
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

still the same :(

#17
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,800 posts
  • Joined 12-May 07
  • OS:none specified
  • Country: Country Flag
@jaclaz, Since I'm following along, I tried some of these commands as well just trying to learn new things. I'm just running a home machine Win7 x86 Ultimate, if it matters.

Anyway, I got similar results to TheWalrus for the "second" command you suggested, and for your latest suggestion I got

Invalid XSL format <or> file name.

What should we be getting?

Cheers and Regards

Posted Image


#18
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,655 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
The /format: switch changes the format of the output.
Examples:
http://waynes-world-...and-format.html
It seems like something has changed in Windows 7, but cannt say what, if either syntax dod not worlk for you. :ph34r:

As an example what I get on my machine with:

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

is:

C:\test>wmic path Win32_networkadapterconfiguration where "IPENABLED=TRUE" get
Caption,SettingID
Caption SettingID

[00000008] Atheros L1 Gigabit Ethernet 10/100/1000Base-T Controller {4E1252DC-1
884-4B8E-BFF4-B016E790CCF4}


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

I get:

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

Node,Caption,SettingID
CINQUE,[00000008] Atheros L1 Gigabit Ethernet 10/100/1000Base-T Controller,{4E12
52DC-1884-4B8E-BFF4-B016E790CCF4}

(i.e. an easy parsable CSV)

What do you get if you issue:
http://isc.sans.edu/...ml?storyid=1229
wmic process list /format /?
:unsure:

You should get a number of "keywords".



jaclaz

#19
iamtheky

iamtheky

    Friend of MSFN

  • Member
  • PipPipPipPipPip
  • 866 posts
  • Joined 11-November 08
I would still go simple using the Find command to filter as needed, the IPenabled=true whittles it down greatly as well. but using the miniports as example

wmic nic get name | find /i "miniport"

wmic nic get name | find /i "miniport" | find /i "WAN"

wmic nic get name | find /i "miniport" | find /i "WAN" | find /i "L2TP"

but in your case i think it might be easier to work with what is not included, thus post #5 or a more generic:

wmic nic where netconnectionID="Local Area Connection" get name | find /V "VPN"


Setting this return, and using it in reg query however.... I'm rooting for that next, I need to learn.

Edited by iamtheky, 30 August 2011 - 08:20 AM.

iamtheKy

#20
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,800 posts
  • Joined 12-May 07
  • OS:none specified
  • Country: Country Flag

What do you get if you issue:

wmic process list /format /?
:unsure:

You should get a number of "keywords".


I do.

Keyword/XSL filename to process XML results.

USAGE:

/FORMAT:<format specifier>

NOTE: <formatspecifier> : ((<transformname>|<transformname> : <paramstring>)[,<formatspecifier>]).

where <paramstring><img src='http://www.msfn.org/board/public/style_emoticons/<#EMO_DIR#>/sad.gif' class='bbc_emoticon' alt=':(' />(<parametername>=<value>)[:<paramstring>]).

NOTE: <transformname> is a <key word> or an <xsl file name>.

Keywords:

CSV
HFORM
HTABLE
LIST
MOF
RAWXML
TABLE
VALUE
XML
htable-sortby
htable-sortby.xsl
texttablewsys
texttablewsys.xsl
wmiclimofformat
wmiclimofformat.xsl
wmiclitableformat
wmiclitableformat.xsl
wmiclitableformatnosys
wmiclitableformatnosys.xsl
wmiclivalueformat
wmiclivalueformat.xsl

Cheers and Regards

Posted Image


#21
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,655 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

I do.

Then there is no reason why it shouldn't work.
Each and every keyword:

CSV
HFORM
HTABLE
LIST
MOF
RAWXML
TABLE
VALUE
XML

corresponds to an available "format", i.e. a valid parameter of the /format:<keyword>.
Can you try with some other of the keywords?
Example of my output with RAWXML:
C:\test>wmic path Win32_networkadapterconfiguration where "IPENABLED=TRUE" get
Caption,SettingID /format:rawxml
<COMMAND SEQUENCENUM="1" ISSUEDFROM="CINQUE" STARTTIME="08-30-2011T16:44:44" EVE
RYCOUNT="0"><REQUEST><COMMANDLINE> path Win32_networkadapterconfiguration where
"IPENABLED=TRUE" get  Caption,SettingID /format:rawxml</COMMANDLINE>
<COMMANDLINECOMPONENTS><NODELIST><NODE>CINQUE</NODE>
</NODELIST>
</COMMANDLINECOMPONENTS>
<CONTEXT><NAMESPACE>root\cimv2</NAMESPACE>
<ROLE>root\cli</ROLE>
<IMPLEVEL>IMPERSONATE</IMPLEVEL>
<AUTHLEVEL>PKTPRIVACY</AUTHLEVEL>
<LOCALE>ms_410</LOCALE>
<PRIVILEGES>ENABLE</PRIVILEGES>
<TRACE>OFF</TRACE>
<RECORD>N/A</RECORD>
<INTERACTIVE>OFF</INTERACTIVE>
<FAILFAST>OFF</FAILFAST>
<OUTPUT>STDOUT</OUTPUT>
<APPEND>STDOUT</APPEND>
<USER>N/A</USER>
<AGGREGATE>ON</AGGREGATE>
</CONTEXT>
</REQUEST>
<RESULTS NODE="CINQUE"><CIM><INSTANCE CLASSNAME="Win32_NetworkAdapterConfigurati
on"><PROPERTY NAME="Caption" TYPE="string"><VALUE>[00000008] Atheros L1 Gigabit
Ethernet 10/100/1000Base-T Controller</VALUE>
</PROPERTY>
<PROPERTY NAME="SettingID" TYPE="string"><VALUE>{4E1252DC-1884-4B8E-BFF4-B016E79
0CCF4}</VALUE>
</PROPERTY>
</INSTANCE>
</CIM>
</RESULTS>
</COMMAND>

I have no idea why the CSV option is not working for you. :w00t:


Try checking contents of file %WINDIR%\system32\wbem\xsl-mappings.xml (if any):
http://technet.micro...755(WS.10).aspx
http://technet.micro...974(WS.10).aspx
And if you have a %WINDIR%\system32\wbem\csv.xsl file.
And if you have %WINDIR%\system32\wbem\ in path.
(or try navigating to %WINDIR%\system32\wbem\ and run WMIC in it)

jaclaz

Edited by jaclaz, 03 September 2011 - 10:23 AM.


#22
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,800 posts
  • Joined 12-May 07
  • OS:none specified
  • Country: Country Flag
As is often the case, I reran your third suggested command, jaclaz:

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

and got an output this time:

Node,Caption,SettingID
COMP,[00000007] Broadcom NetXtreme Gigabit Ethernet,{DAF2CE16-5B38-4AFF-BF3B-FD3A4AD9D28A}
COMP,[00000012] VMware Virtual Ethernet Adapter for VMnet1,{34E15011-CC8B-4568-8B26-FB3006AC01A4}
COMP,[00000013] VMware Virtual Ethernet Adapter for VMnet8,{001DA8BB-0E77-4622-BA99-0BC59B2417D0}

Won't try to guess why it worked this time but not before. So anyway, I guess it should work for you as well, TheWalrus?

Cheers and Regards

Posted Image


#23
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,655 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

Won't try to guess why it worked this time but not before. So anyway, I guess it should work for you as well, TheWalrus?

I seem (vaguely) to remember that on first EVER execution of a WMI (or WMIC) query/command on a system the WBEM (whatever it is) is *somehow* "initialized".
Maybe this is the case. :unsure:

http://ss64.com/nt/wmic.html

When you type WMIC for the first time in Windows 2003 all the aliases are compiled. The second, and subsequent times you run WMIC, it will start immediately. Under XP WMIC is slower to initialise, therefore to run several WMI queries it can be quicker to use interactive mode.


Or maybe it is an Administrator/UAC/permission issue?

Anyway, now that it works, run it like this:
wmic path Win32_networkadapterconfiguration get /format:csv>C:\test\test.csv

and open/import the resulting .csv file in *any* spreadsheet program.

This way you will see easily all the info that is coming from the command and see which conditions you can use in the query and which fields are to be retrieved.

Generic query syntax is:
wmic path <wmi path> where <condition> get <comma separated fields you want to retrieve>


jaclaz

#24
Octopuss

Octopuss

    I am the walrus

  • Member
  • PipPipPipPipPipPip
  • 1,127 posts
  • Joined 31-January 07
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

tried running the command several times in a row, on work and home computers both, and still the same error message :(

(UAC off, using local admin account)



edit: if I skip the whole /format part, I do get some results.


Edited by TheWalrus, 01 September 2011 - 01:23 PM.


#25
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,655 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

tried running the command several times in a row, on work and home computers both, and still the same error message :(

(UAC off, using local admin account)



edit: if I skip the whole /format part, I do get some results.

This is a mistery, since it came out as working for bphlpt :w00t:
I really have no idea why it does not work for you.

Have you actually tried the suggested checks?:

Try checking contents of file %WINDIR%\system32\wbem\xsl-mappings.xml (if any):
http://technet.micro.../cc778755(WS.10).aspx
http://technet.micro.../cc784974(WS.10).aspx
And if you have a %WINDIR%\system32\wbem\csv.xsl file.
And if you have %WINDIR%\system32\wbem\ in path.
(or try navigating to %WINDIR%\system32\wbem\ and run WMIC in it)


jaclaz

Edited by jaclaz, 03 September 2011 - 10:24 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users