#28131 - 2002-08-30 02:20 AM
How Do I locate and use the next available registry value
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11628
Loc: CA
|
I know I can use something like either IF or SELECT, but is there another (better) way to enumerate the current values and then create and populate the next available one?
i.e.
HKLM\Software\MyCompnayStuff 1 SM-FILE1 2 SM-DATA 3 SM-HARDWARE 4 5 SOFTWARE 6 PHONE
In the example above I would want to find that the string value of 6 was already in use and now the number 7 is the next available value that I should add and populate. Notice that 4 is empty so using <>"" test would not be valid alone.
I'm using KiXtart v4.02 currently, soon to be 4.11
Ok, reading manual I found this. I'll work on this idea. I never noticed this command before.
code:
$Index = 0 :Loop1 $ValueName = ENUMVALUE("HKEY_CURRENT_USER\Console\Configuration", $Index) If @ERROR = 0 ? "Name found: $ValueName" $Index = $Index + 1 goto Loop1 Endif
[ 30. August 2002, 02:39: Message edited by: NTDOC ]
|
|
Top
|
|
|
|
#28132 - 2002-08-30 03:03 AM
Re: How Do I locate and use the next available registry value
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11628
Loc: CA
|
Okay... I worked out a solution.
code:
Break On $Index = 0 While @ERROR = 0 $ValueName = ENUMVALUE("HKEY_CURRENT_USER\Console\Configuration", $Index) $Index = $Index + 1 Loop $x=WriteValue("HKEY_CURRENT_USER\Console\Configuration", $Index, "", "REG_SZ")
|
|
Top
|
|
|
|
#28140 - 2002-08-30 11:05 PM
Re: How Do I locate and use the next available registry value
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11628
Loc: CA
|
Jens,
Your arrayenumvalue is pulling the Value, not the data string in the value of the Registry.
1 is the value custom.dic is the data string in the value.
i.e. 1 2 3 4 5
etc... is the Value for this Registry Key HKEY_CURRENT_USER\Software\Microsoft\Shared Tools\Proofing Tools\Custom Dictionaries
Then CUSTOM.DIC is the entry for number 1 normally, but then users could enter or have any number of additional custom dictionaries for MS Office.
I want to find out what the data in 1, 2, 3, etc.. is and if it finds MyCustom.dic then do nothing, if it is not found I want to go ahead and create the next available number and insert my text string of MyCustom.dic into that number value.
i.e. This needs to prevent duplicates and overwrites.
Does anyone have any other ideas on how to accomplish this?
Howard, Jens, Rad, Bryce, Chris, Jochen, others?
|
|
Top
|
|
|
|
#28142 - 2002-09-01 03:46 PM
Re: How Do I locate and use the next available registry value
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
NTDOC, take a look at at Pseudo Hash UDFs (Hash & MHash) - RFC . I think that the ability to place MyCustom.dic as the hash key will eliminate the possiblity of duplicates. You can EnumValue/ReadValue into the hash construct. If you decide to use this approach, you may need some supporting functionality like HashKeys($HashName) and DelHashKey($HashName, $Key). In that case let me know and I will discuss your requirements and post the necessary code.
|
|
Top
|
|
|
|
#28143 - 2002-09-02 03:26 AM
Re: How Do I locate and use the next available registry value
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Well, I may not be an array master, but I think I have something for your custom dictionary problem. Give this a try...
code:
Break On CLS $EnumRegKey = "HKCU\Software\Microsoft\Shared Tools\Proofing Tools\Custom Dictionaries" $Find = "MyCustom.dic" $Index = 0 Dim $ValueName[100], $ValueData[100] While @ERROR = 0 $ValueName[$Index] = ENUMVALUE($EnumRegKey, $Index) $ValueData[$Index] = READVALUE($EnumRegKey, $ValueName[$Index]) If $ValueData[$Index] = $Find $Found = 1 Endif If @ERROR = 0 $Index = $Index + 1 Endif If $Index = ubound($ValueName) ReDim Preserve $ValueName[$Index+100], Preserve $ValueData[$Index+100] Endif Loop $Index = $Index -1 ReDim Preserve $ValueName[$Index], Preserve $ValueData[$Index] If Not $Found $nul = WRITEVALUE($EnumRegKey, val($ValueName[ubound($ValueName)])+1, $Find, "REG_SZ") If @ERROR "Error Adding: " + $Find ? Else "Added $Find to the Custom Dictionary key." ? Endif Else $Find " is already in the Custom Dictionary key." ? Endif
[ 02. September 2002, 15:32: Message edited by: Chris S. ]
|
|
Top
|
|
|
|
#28144 - 2002-09-02 04:40 AM
Re: How Do I locate and use the next available registry value
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Chris, your logic is close to that of the code I envisioned using my hash code.
You need to review your use of "ReDim Preserve $ValueName[$Index+100], $ValueData[$Index+100]". This statement will not preserve the data in $ValueData[$Index+100]. You need to use "preserve" before each array listed in the ReDim.
|
|
Top
|
|
|
|
#28146 - 2002-09-02 03:12 PM
Re: How Do I locate and use the next available registry value
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
See this link: KiX2001.411rc1 Bug -> Redim Preserve
I did not see any other posts that said this had been changed.
|
|
Top
|
|
|
|
#28147 - 2002-09-02 03:35 PM
Re: How Do I locate and use the next available registry value
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Maybe it was the way I was testing it. I was echoing results right after I populated the element, so maybe it just looked like array was preserved. Anyway, I believe you and Ruud, so I changed the code.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 989 anonymous users online.
|
|
|