any idea howto retrieve the GUID of network card in a script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Matice

any idea howto retrieve the GUID of network card in a script

#1 Post by Matice » 19 Sep 2006 23:44

greetz,

im facing an issue where i want to accomplish something (enabling to display the network connection status in the taskbar) but for me to be able to write the correct registry key, i need ot retrieve the GUID of the network device.

my question is, is there a trick on how to retrieve the GUID?

i found the following script but for some reason, it doesnt seem to work any ideas?

http://www.jsifaq.com/SF/Tips/Tip.aspx?id=8270

regards
Matice

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 21 Sep 2006 21:58

Matice,

Use the :NetworkDeviceName2Guid function in you main code like this:

Code: Select all

CALL:NetworkDeviceName2Guid "Local Area Connection" guid
ECHO.The GUID is: %guid%
GOTO:EOF


Copy the :NetworkDeviceName2Guid function from here:
http://www.dostips.com/DtCodeCmdLib.php#NetworkDeviceName2Guid
to the end of your batch file.

DOS IT HELP?

Matice

#3 Post by Matice » 22 Sep 2006 01:48

greetz,

for some reason i wasnt able to get it to work, i guess it has to do with the different reg.exe version being used in different OS, in my case windows server 2003.

here is what i was able to cut down to:

ECHO # Enabling "Show Icon in Notification Area When Connected" for WEB, SRVR and BKP NIC Interfaces
reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318} /s|findstr "\Connection"|sed -e "s/HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\//g"|sed -e "s/\\Connection//g" > c:\nicguid.txt
for /f %%i in (c:\source\nicguid.txt) do reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\%%i\Connection /v Name|findstr /I "WEB SRVR BKP" > NUL && if errorlevel 0 ECHO FOUND PROD NIC CONFIGURING .. && REG.EXE ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\%%i\Connection" /f /v "ShowIcon" /t REG_DWORD /d "1"
del c:\nicguid.txt
echo Modifications applied and will be active on next boot!


i guess that could be improved and use something other than sed but i just found sed easier.. bash is just so much easier and more flexible.. well at least it has more documentation to the different tweaks available.

this site has some very impresive implementations that i have not seen elsewhere.

your kungfuu is strong!!!

regards
Matice

DosItHelp wrote:Matice,

Use the :NetworkDeviceName2Guid function in you main code like this:

Code: Select all

CALL:NetworkDeviceName2Guid "Local Area Connection" guid
ECHO.The GUID is: %guid%
GOTO:EOF


Copy the :NetworkDeviceName2Guid function from here:
http://www.dostips.com/DtCodeCmdLib.php#NetworkDeviceName2Guid
to the end of your batch file.

DOS IT HELP?

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#4 Post by DosItHelp » 23 Sep 2006 20:34

Matice,

:idea: Your code is creating data in c:\nicguid.txt but then tries to read it from c:\source\nicguid.txt.

A regular expression parser surely is a powerful tool. However this web page tries to suggest portable solution that work on XP systems without extra downloads. :D

Matice

#5 Post by Matice » 25 Sep 2006 00:27

thats why i posted back here :)
there is a lot that i could with posix tools that are very hard to implement with in windows.. im just trying to minimize the gap and use windows resources as much as possible

Post Reply