~ How to get Unique GUID value in Batch? ~

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

~ How to get Unique GUID value in Batch? ~

#1 Post by Dos_Probie » 20 Sep 2012 08:15

Trying to extract network info (see Working and Non-Working Scripts Below), only problem is it needs the {GUID} and I don't know that going in as it changes from computer to computer, How can I retrieve the {GUID} value and then echo back the correct information?
Thanks for the help..Dos_Probie :roll:

Some examples which are similiar but not the same..
viewtopic.php?f=3&t=1734
http://mykbit.blogspot.com/2009/11/unin ... emote.html


Code: Select all

@echo off&color e
SETLOCAL ENABLEEXTENSIONS
title,==NETWORK INFORMATION!==

::WORKING-Once I have the Correct GUID

:: Query Wireless Profile Name with Exsisting GUID then echo back Info::
set qry=reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles\{53EF403B-0E9C-4BE6-BCCF-67A45439006C}" /v ProfileName
set fnd=findstr /I /L /C:"REG_SZ"
for /f "Tokens=2*" %%u in ('%qry%^|%fnd%') do (@echo Your Profile Name Is: %%v)
echo.
pause


::NOT WORKING-This is what I have so far to find {GUID} but it just flashes error..
for /f "tokens=7 delims=\" %%a in ('reg query HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles ^| FIND "{"') do
for /f "tokens=2,*" %%c in ('reg query HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles\%%a ^| find /i "ProfileName"') do
echo %%d,%%a>>PROFILE.NAME.txt
echo.
pause
exit
Last edited by Dos_Probie on 23 Sep 2012 21:30, edited 2 times in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: ~ How to get Unique GUID value in Batch? ~

#2 Post by foxidrive » 20 Sep 2012 08:39

It errors because "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles" does not have quotes around it.

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: ~ How to get Unique GUID value in Batch? ~

#3 Post by Dos_Probie » 20 Sep 2012 10:39

foxidrive wrote:It errors because "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles" does not have quotes around it.


Foxi, I thought the same thing but when I add quotes still flashes and not working..
Have you got example that will work?

Code: Select all

::NOT WORKING-This is what I have so far to find {GUID} but it just flashes error..
for /f "tokens=7 delims=\" %%a in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles" ^| FIND "{"') do
for /f "tokens=2,*" %%c in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles"\%%a ^| find /i "ProfileName"') do
echo %%d,%%a>>PROFILE.NAME.txt
echo.
pause

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: ~ How to get Unique GUID value in Batch? ~

#4 Post by foxidrive » 20 Sep 2012 10:54

The mistake you made was to forget the DO ( ... ) parentheses.

This works here:

Code: Select all

@echo off
for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles" ^| FIND "{"') do (
for /f "tokens=2,*" %%b in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles\%%~nxa" ^| FIND "ProfileName"') do echo %%~nxa,%%c
)
pause

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: ~ How to get Unique GUID value in Batch? ~

#5 Post by Dos_Probie » 20 Sep 2012 11:31

Ok, Gotcha...Thanks!
getting closer that lists Both GUIDs, anyway to just list one ? :?:

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: ~ How to get Unique GUID value in Batch? ~

#6 Post by foxidrive » 20 Sep 2012 11:44

First or second?

is this for your own machine or for distribution - do you have to handle more than 2 GUIDs?

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: ~ How to get Unique GUID value in Batch? ~

#7 Post by Dos_Probie » 20 Sep 2012 16:13

The First GUID and only need to handle one.. 8)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: ~ How to get Unique GUID value in Batch? ~

#8 Post by foxidrive » 20 Sep 2012 19:26

This works here:

Code: Select all

@echo off
for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles" ^| FIND "{"') do set var=%%~nxa&goto :gotit
:gotit
for /f "tokens=2,*" %%b in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles\%var%" ^| FIND "ProfileName"') do echo %var%,%%c
pause

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: ~ How to get Unique GUID value in Batch? ~

#9 Post by Dos_Probie » 23 Sep 2012 15:11

foxidrive wrote:This works here:

Code: Select all

@echo off
for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles" ^| FIND "{"') do set var=%%~nxa&goto :gotit
:gotit
for /f "tokens=2,*" %%b in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles\%var%" ^| FIND "ProfileName"') do echo %var%,%%c
pause


Thanks for the code Foxi, it gives Both the Guid and the Network name.. anyway to just show
the Network Name: :?:

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: ~ How to get Unique GUID value in Batch? ~

#10 Post by Dos_Probie » 23 Sep 2012 17:47

What exactly does the %%~nxa variable do :?: ?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: ~ How to get Unique GUID value in Batch? ~

#11 Post by foxidrive » 23 Sep 2012 18:47

Dos_Probie wrote:
foxidrive wrote:This works here:

Code: Select all

@echo off
for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles" ^| FIND "{"') do set var=%%~nxa&goto :gotit
:gotit
for /f "tokens=2,*" %%b in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles\%var%" ^| FIND "ProfileName"') do echo %var%,%%c
pause


Thanks for the code Foxi, it gives Both the Guid and the Network name.. anyway to just show
the Network Name: :?:


Remove %var%, from the echo command.

Dos_Probie wrote:What exactly does the %%~nxa variable do :?: ?


It returns the last part of a string where the sting has \ or / as delimiters. It returns the name and extension, if it has one. That is what the nx means in the variable - check the help FOR /? and read the last couple of pages for the other metavariables.

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: ~ How to get Unique GUID value in Batch? ~

#12 Post by Dos_Probie » 23 Sep 2012 19:21

Ok, Thanks got it! :mrgreen:

Code: Select all

@echo off&color e
SETLOCAL ENABLEEXTENSIONS
title,==NETWORK INFORMATION!==

:: ISP Domain
for /f "tokens=2 delims=:" %%# In ('IPConfig /all^|Find "DNS Suffix Search List"') Do (
for %%$ In (%%#) Do Set ISPDomain=%%$)
echo=Your ISP Domain Is: %ISPDomain%
echo.

:: IP Address
for /f "tokens=2 delims=:" %%# In ('IPConfig^|Find "IPv4"') Do (
Call :Addy %%#)
:Addy
Set IP=%1
Echo=Your IP Address Is: %IP%
echo.

:: Network Profile Name
for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles" ^| FIND "{"') do set var=%%~nxa&goto :gotit
:gotit
for /f "tokens=2,*" %%b in ('reg query "HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\networklist\Profiles\%var%" ^| FIND "ProfileName"') do echo Your Active Profile Name Is: %%%c

pause>nul

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: ~ How to get Unique GUID value in Batch? ~

#13 Post by Dos_Probie » 23 Sep 2012 22:42

Foxi, I need to use the Second guid on another query so How did you determine to use either the first guid or the second guid ?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: ~ How to get Unique GUID value in Batch? ~

#14 Post by foxidrive » 24 Sep 2012 03:30

Take out the &goto :gotit and it will take the last one. %var% will contain the information.



If there will ever be three or more then more extensive coding is needed.

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: ~ How to get Unique GUID value in Batch? ~

#15 Post by Dos_Probie » 24 Sep 2012 08:21

Ok, Thanks .. That's What I had already figured out b4 you posted..The below code has multiple
guids +3 so shows more than one.. :cry:


Code: Select all

@echo off&color e
SETLOCAL ENABLEEXTENSIONS
title,==NETWORK INFORMATION!==

::cks online or offline

::Lists both 192.xxx.x.xx and 0.0.0.0 (Need only the 192.xxx)
for /f "delims=" %%a in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces" ^| FIND "{"') do (
for /f "tokens=2,*" %%b in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\%%~nxa" ^| FIND "DhcpIPAddress"') do echo %%c
)

Post Reply