Jump to content

Need help making a reg query batch.


Recommended Posts

I need to find out the keystring of my WLAN NIC using a batch query, as I believe this changes on each install.

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\13]
"ServiceName"="{65FA9572-A7DB-42EE-8EC5-1D1D41E299FA}"
"Description"="Intel(R) PRO/Wireless 2200BG Network Connection"

So I need a batch that search for Description "Intel® PRO/Wireless 2200BG Network Connection" in HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\XX and then return the ServiceName value ({65FA9572-A7DB-42EE-8EC5-1D1D41E299FA}).

Please help me out here! Ive really tried myself but cant figure it out. Yzöwl, I know you know this hehe care to help out?

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
:// Set the description of NIC to find ServiceName
SET NIC="Intel(R) PRO/Wireless 2200BG Network Connection"
for /F "tokens=7 delims=\" %%I in ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards" ') do call :NIC %%I
GOTO :EOF

:NIC
:// 3 tokens are ValueName Type Value under selected Key
:// delims is a tab delimiter
for /F "tokens=3 delims= " %%I in ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\%1" /v "Description" ^| findstr "REG_SZ" ') do set Description="%%I"
for /F "tokens=3 delims= " %%J in ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\%1" /v "ServiceName" ^| findstr "REG_SZ" ') do set ServiceName="%%J"
IF %description%==%NIC% echo.%ServiceName%

:EOF

Yzöwl, your welcome to rewrite it better, you are MSFN batch expert. ;)

Link to comment
Share on other sites


firstly Bilou, lets look at the wmic methods from earlier in the thread...

Try this

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
FOR /F "USEBACKQ SKIP=1" %%? IN (
`WMIC NICCONFIG WHERE "MACADDRESS='00:0E:35:2C:20:A7'" GET SETTINGID ^2^>NUL`
) DO (
IF ERRORLEVEL 0 SET SVCNAME=%%?
)
IF DEFINED SVCNAME ECHO/%SVCNAME%
ENDLOCAL
GOTO :EOF

or using the description

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
FOR /F "USEBACKQ SKIP=1" %%? IN (
`WMIC NICCONFIG WHERE "DESCRIPTION='Intel(R) PRO/Wireless 2200BG Network Connection'" GET SETTINGID ^2^>NUL`
) DO (
IF ERRORLEVEL 0 SET SVCNAME=%%?
)
IF DEFINED SVCNAME ECHO/%SVCNAME%
ENDLOCAL
GOTO :EOF

<Edit>

Bilou, I nearly forgot

@ECHO OFF &SETLOCAL ENABLEEXTENSIONS

:: Set the description of NIC to find ServiceName
SET "NIC=Intel(R) PRO/Wireless 2200BG Network Connection"

FOR /F "DELIMS=" %%? IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards" ^|FINDSTR \\[0-9]*$ ^2^>NUL') DO IF ERRORLEVEL 0 CALL :NIC "%%?"
IF DEFINED SvcName (ECHO/%SvcName% &PING -n 11 127.0.0.1 >NUL)
ENDLOCAL &GOTO :EOF

:NIC
REG QUERY "%~1" /v "Description" |FINDSTR/I "%NIC%" >NUL 2>&1 ||GOTO :EOF
:: 3 tokens are Name Type and Data under selected Key
:: delims is a tab delimiter
FOR /F "SKIP=1 TOKENS=3 DELIMS= " %%? IN ('REG QUERY "%~1" /v "ServiceName" ^2^>NUL') DO IF ERRORLEVEL 0 SET SvcName=%%?
GOTO :EOF

</Edit>

Edited by Yzöwl
Link to comment
Share on other sites

Study WMIC, it is really awesome command...

hi, is there a way to set registry keys using wmic?!

one can do really amazing stuff with the wmic commands, but i don't find a possibility to edit/create/delete reg.keys.. maybe someone could help me.

thx in advance

would appreciate some attention :hello: anyone?!

Link to comment
Share on other sites

If as you have already stated

WMIC NicConfig Where Description="Intel(R) PRO /Wireless 2200BG Network Connection - Miniport for pakkeplanlegger" GET MTU

works, then there's is no problem with WHERE!

is this line correct?
WMIC NicConfig Where MACAddress="00:0E:35:2C:20:A7" Set SetMTU = 1500

Now look at mine
WMIC NICCONFIG WHERE MACADDRESS="00:0E:35:2C:20:A7" CALL SETMTU 1500

there's no space=space before the MTU value.

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