Page 1 of 2 12>
Topic Options
#28131 - 2002-08-30 02:20 AM How Do I locate and use the next available registry value
NTDOC Administrator Offline
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 Offline
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
#28133 - 2002-08-30 04:32 AM Re: How Do I locate and use the next available registry value
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Hmmm.... that code works fine to create it, but now how do I check for it and stop it from creating if it already exists.

If it was always the same number I could check for it, but since it can be in any number value

1 software
2 custom
3 hardware
4 mystuff
etc... how can I enum and check for say hardware, and not create another value if it exists?

[ 30. August 2002, 04:34: Message edited by: NTDOC ]

Top
#28134 - 2002-08-30 04:49 AM Re: How Do I locate and use the next available registry value
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Use the ArrayEnumValue() UDF to populate the values into an array. Then check the presence of a specific value in the array with the IsInArray() UDF. The next available number will be UBOUND($Array).

[ 30. August 2002, 19:28: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#28135 - 2002-08-30 10:53 AM Re: How Do I locate and use the next available registry value
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Jens,

You make it sound easy, but I can not find the IsInArrray() udf on this board or the ScriptLogic board. ScriptLogic has one that looks like it may be the one you're talking about.

ASCAN.UDF

Do you have the file, or a link to it?

Top
#28136 - 2002-08-30 04:46 PM Re: How Do I locate and use the next available registry value
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
There you go: IsInArray() - Checks if a string is part of a array of strings

You can find it by using the BBS Search, search for IsInArray in 'UDF Forum Only' and 'Subject Only'.

BTW, you might need to reformat your array a little bit since the IsInArray only compares complete strings. so you might need to get rid of the preceeding numbers and the hyphen.
_________________________
There are two types of vessels, submarines and targets.

Top
#28137 - 2002-08-30 07:03 PM Re: How Do I locate and use the next available registry value
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Jens,

I know how to use the search feature... what I did not notice is that your original post has 3 r's in it (IsInArrray) naturally search did not find it.

Your post today shows it as 2 r's so it finds it right away.

What is weird though, is that I searched for array and it had a LOT of hits (164) (stupid search engine) then I posted the IsInArrray to the CTRL-F search function of IE (which again did not find that UDF)

Anyways... I'll check them out and see if I can get them to work or not.

Top
#28138 - 2002-08-30 07:29 PM Re: How Do I locate and use the next available registry value
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Sorry for the spelling error [Embarrassed]

Hope it works out for you.
_________________________
There are two types of vessels, submarines and targets.

Top
#28139 - 2002-08-30 08:14 PM Re: How Do I locate and use the next available registry value
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
No problem Jens... I sent you an email
Top
#28140 - 2002-08-30 11:05 PM Re: How Do I locate and use the next available registry value
NTDOC Administrator Offline
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
#28141 - 2002-09-01 10:20 AM Re: How Do I locate and use the next available registry value
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Any of you ARRAY MASTERS out there got an idea how to do this.

Hopefully someone can figure out a better way, otherwise I'll be back to using a bunch of SELECT statements that won't be that slick... but should get me by.

Thanks for any other help.

Top
#28142 - 2002-09-01 03:46 PM Re: How Do I locate and use the next available registry value
Howard Bullock Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#28143 - 2002-09-02 03:26 AM Re: How Do I locate and use the next available registry value
Chris S. Offline
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 Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#28145 - 2002-09-02 03:05 PM Re: How Do I locate and use the next available registry value
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Hmm. It was working ok for me, but I am using 4.11.
Top
#28146 - 2002-09-02 03:12 PM Re: How Do I locate and use the next available registry value
Howard Bullock Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#28147 - 2002-09-02 03:35 PM Re: How Do I locate and use the next available registry value
Chris S. Offline
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. [Wink]
Top
#28148 - 2002-09-02 08:40 PM Re: How Do I locate and use the next available registry value
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Well Chris (you're more of an Array Master then me) it seems to work well for me. I'll add some code to check the office versions and os types (the file goes into different locations based on os and the registry gets updated based on different office version) then I'll let you know how it all goes.

Thank you very much.

I was thinking I could do what you did, i.e. read the data along with the value, but I did not know how or if they would stay linked together.

Howard thanks for the information and idea as well.

Top
#28149 - 2002-09-03 05:07 PM Re: How Do I locate and use the next available registry value
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Hmm, so you want ot have the keys enumerated, not the values?
ArrayEnumKey() does for registry keys what ArrayEnumValue does for registry values [Wink]
_________________________
There are two types of vessels, submarines and targets.

Top
#28150 - 2002-09-03 08:08 PM Re: How Do I locate and use the next available registry value
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Jens,

There are KEYS - VALUES - DATA in the Registry.

HKLM - KEY
HKLM\SOFTWARE - KEY
HKLM\SOFTWARE\STUFF - KEY
-> LocalPath - VALUE
-> AutoStart - VALUE
-> AutoStart [true] - DATA (true is the data]

You need the ENUMVALUE which you have a UDF for, but then you also need an ENUMDATA

i.e. ENUMKEY, ENUMVALUE, ENUMDATA The ENUMDATA is missing from the picture that would have solved this issue.

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 809 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.07 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org