Shawndt Posted January 27, 2011 Share Posted January 27, 2011 Good Morning, I am trying to read the registry. My problem is the keys inside the {} Brackets. Is there a way to automatically read these without coding each and everyone? As each one would be different for every user. I am sure I am not the only one that has had this problem. I am looking for DNS entries for Wireless or Lan setting. The key that I am searching is HKLM\system\currentcontrolset\services\tcpip\parameters\interfaces. I am trying to return the NAMESERVER value. for each of the keys under interfaces. I cannot figure this one out. Please help! Thank you for your kind attention. Link to comment Share on other sites More sharing options...
iamtheky Posted January 27, 2011 Share Posted January 27, 2011 There is no doubt a nicer way to go about this. But enumerating the keys then looping through them is what you are aiming for. #include <array.au3> Dim $keys[1] for $i = 1 to 100 $reg = RegEnumKey ("HKLM\system\currentcontrolset\services\tcpip\parameters\interfaces\" , $i) If $reg = '' Then exitloop Else _ArrayAdd ($keys , $reg) Endif next _ArrayDelete ($keys , 0) Dim $Servers[1] for $k = 0 to ubound($keys) - 1 $Name = regread ("HKLM\system\currentcontrolset\services\tcpip\parameters\interfaces\" & $keys[$k] , "NameServer") If $Name = "" then $Name = "No NameServer Entry" _ArrayAdd ($Servers , $keys[$k] & "\\\\\\\" & $Name) Next _ArrayDelete ($Servers , 0) _ArrayDisplay ($Servers) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
GEOSoft Posted January 27, 2011 Share Posted January 27, 2011 This will do it but be sure to read the comments. The nice part here is you don't have to include that ugly Array.au3 file except to use _ArrayDisplay() which you probably won't need in your code. expandcollapse popupOpt("MustDeclareVars", 1) #Include<Array.au3> ;; Only used for the _ArrayDisplay() below Global $sRegKey = "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" Local $aNameServers = _DNS_ToArray(True);; You won't need any parameter here if the commented conditional is removed in the function If NOT @Error Then _ArrayDisplay($aNameServers) Else MsgBox(4096, "Error", "No valid NameServerEntries were found") EndIf Func _DNS_ToArray($i_Inc_Keys = False);; Returns a 0 based array Local $i = 1, $sVals = "", $sCur_Val, $sHold, $sKeys = "", $aRtn, $aVals, $aKeys While 1 $sHold = RegEnumKey($sRegKey, $i) If @Error Then ExitLoop $sCur_Val = RegRead($sRegKey & $sHold, "NameServer") If NOT @Error Then If $sCur_Val <> "" Then $sVals &= $sCur_Val & "|" $sKeys &= $sHold & "|";; All references to $sKeys can be removed if you remove the conditional noted below EndIf EndIf $i +=1 WEnd $aVals = StringSplit(StringTrimRight($sVals, 1), "|") If @Error Then Return(SetError(1)) If NOT $i_Inc_Keys Then ;; If you will never need to know the keys this whole conditional and the parameter $i_Inc_keys can be removed $aRtn = $aVals Else $aKeys = StringSplit(StringTrimRight($sKeys, 1), "|") Dim $aRtn[UBound($aKeys)][2] For $i = 1 To UBound($aKeys) -1 $aRtn[$i][0] = $aKeys[$i] $aRtn[$i][1] = $aVals[$i] Next EndIf Return ($aRtn) EndFunc George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Shawndt Posted January 28, 2011 Author Share Posted January 28, 2011 There is no doubt a nicer way to go about this. But enumerating the keys then looping through them is what you are aiming for. #include <array.au3> Dim $keys[1] for $i = 1 to 100 $reg = RegEnumKey ("HKLM\system\currentcontrolset\services\tcpip\parameters\interfaces\" , $i) If $reg = '' Then exitloop Else _ArrayAdd ($keys , $reg) Endif next _ArrayDelete ($keys , 0) Dim $Servers[1] for $k = 0 to ubound($keys) - 1 $Name = regread ("HKLM\system\currentcontrolset\services\tcpip\parameters\interfaces\" & $keys[$k] , "NameServer") If $Name = "" then $Name = "No NameServer Entry" _ArrayAdd ($Servers , $keys[$k] & "\\\\\\\" & $Name) Next _ArrayDelete ($Servers , 0) _ArrayDisplay ($Servers) Thank you this worked perfectly! Link to comment Share on other sites More sharing options...
Shawndt Posted January 28, 2011 Author Share Posted January 28, 2011 This will do it but be sure to read the comments. The nice part here is you don't have to include that ugly Array.au3 file except to use _ArrayDisplay() which you probably won't need in your code. expandcollapse popupOpt("MustDeclareVars", 1) #Include<Array.au3> ;; Only used for the _ArrayDisplay() below Global $sRegKey = "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" Local $aNameServers = _DNS_ToArray(True);; You won't need any parameter here if the commented conditional is removed in the function If NOT @Error Then _ArrayDisplay($aNameServers) Else MsgBox(4096, "Error", "No valid NameServerEntries were found") EndIf Func _DNS_ToArray($i_Inc_Keys = False);; Returns a 0 based array Local $i = 1, $sVals = "", $sCur_Val, $sHold, $sKeys = "", $aRtn, $aVals, $aKeys While 1 $sHold = RegEnumKey($sRegKey, $i) If @Error Then ExitLoop $sCur_Val = RegRead($sRegKey & $sHold, "NameServer") If NOT @Error Then If $sCur_Val <> "" Then $sVals &= $sCur_Val & "|" $sKeys &= $sHold & "|";; All references to $sKeys can be removed if you remove the conditional noted below EndIf EndIf $i +=1 WEnd $aVals = StringSplit(StringTrimRight($sVals, 1), "|") If @Error Then Return(SetError(1)) If NOT $i_Inc_Keys Then ;; If you will never need to know the keys this whole conditional and the parameter $i_Inc_keys can be removed $aRtn = $aVals Else $aKeys = StringSplit(StringTrimRight($sKeys, 1), "|") Dim $aRtn[UBound($aKeys)][2] For $i = 1 To UBound($aKeys) -1 $aRtn[$i][0] = $aKeys[$i] $aRtn[$i][1] = $aVals[$i] Next EndIf Return ($aRtn) EndFunc You rock! This worked as well! Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now