Jump to content

Recommended Posts

Posted
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. ;)


Posted (edited)

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
Posted

I think WHERE is a valid command. I'm not all that familiar with using WMIC, but that's mainly because I access WMI through VBscript rather than through command. What I can say is that WHERE is integral to WMI construct.

Posted

Yes, but I'm pretty sure we determined there was a bug in that release hmm just can't recall what the bug was. I'm pretty sure it was the WHERE statement.

Posted

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?!

Posted

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.

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

Bilou, I nearly forgot

Thanks for the optimized code. I learn the best ways to code from your postings. ;)

About wmic, i can only use it one my full Windows install.

On my Windows XP Embedded runtime image, WMI Command Line Utility isn't added.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...