Solved

Multi String Registry Type

Posted on 1998-12-07
13
585 Views
Last Modified: 2010-04-04
How can I retrieve a multi-string value from the registry?
0
Comment
Question by:Llysander
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
  • +2
13 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 1349721
Hi Llysander,

You can use the GetValues property of a TRefistry object, as it will return a stringlist containing all the datavalues of a key currently selected.

Bruintje.
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1349722
if you're using delphi 2 upwards, that is...

Black Death
0
 

Author Comment

by:Llysander
ID: 1349723
There does not appear to be a GetValues property in TRegistry in Delphi 4.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:philipleighs
ID: 1349724
In D4, it's called GetValueNames
0
 

Author Comment

by:Llysander
ID: 1349725
GetValueNames just gives me a list of the Value names.  I need to be able to retrieve the value data.  I can do that for most data types, but not multi strings.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1349726
Use ReadBinaryData to read the block of data from the registry into a memory block. If this multi string object is essentially an in memory representation of a structure then read it straight into the structure, otherwise you will need to parse it yourself by looking at the length byte and copying the following n bytes into individual strings.

To read it into a structure do this:

TheRegistry.ReadBinaryData('TheKey', TheStructure, sizeof(TheStructure));


Cheers,

Raymond.
0
 

Author Comment

by:Llysander
ID: 1349727
I've tried using a ReadBinary to get the data.  It generates an exception, 'Invalid Data Type';  None of the read methods seem to work either.  I cannot find any registry components that deal with it either, at least ones that don't cost a couple hundred dollars.
0
 

Author Comment

by:Llysander
ID: 1349728
Further information on the question:
Delphi 4.02 attempting to retrive the valuedata from the following key.
HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System
ValueName = SystemBiosVersion
DataType = REG_MULTI_SZ

0
 
LVL 44

Expert Comment

by:bruintje
ID: 1349729
Hi again,

I've build a little project showing a few things in the registry, it's about 6K so I could email it to you.
It will read keys, values and show data types etc.I'm not certain what you mean bij multistrings but I gues subkeys and their values.

So let me know if you're interested.

Bruintje.
0
 
LVL 3

Expert Comment

by:philipleighs
ID: 1349730
A multi string is a chunk of memory where each string is separated by a NULL, and where the whole thing is doubly NULL terminated.

Here is what you want. The function GetMultiStringFromReg fills a string list with the strings, or returns false (or raises exception) otherwise.
It is not the most elegant solution by replacing #0 with #1, but this just makes life easier (can use Pos). StrPas of course treats #0 specially.

It should copy, paste and compile.

procedure MultiStringToStringList(Multi: string; List: TStringList);
  var s: string;
  begin
    while Pos(#1, Multi) > 0 do
      begin
        s := Copy(Multi, 1, Pos(#1, Multi) - 1);
        if s <> '' then
          List.Add(s);
        Delete(Multi, 1, Pos(#1, Multi));
      end;
  end;

function GetMultiStringFromReg(RegPath, RegKey: string; s: TStringList): Boolean;
  var Reg: TRegistry;
      Size: Integer;
      P: PChar;
      DataType: TRegDataType;
      Count: Integer;
begin
  Result := false;
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    if Reg.OpenKey(RegPath, false) then
      begin
        Size := Reg.GetDataSize(RegKey);
        if Size <> -1 then
          begin
            GetMem(P, Size);
            //Originally used ReadBinaryData but got nasty error
            //Use RegQueryValueEx instead
            DataType := rdBinary;
            RegQueryValueEx(Reg.CurrentKey, PChar(RegKey), nil, @DataType, PByte(P), @Size);
            for Count := 0 to Size - 1 do
              if (P + Count)^ = #0 then
                (P + Count)^ := #1;
            MultiStringToStringList(StrPas(P), s);
            FreeMem(P);
            Result := true;
          end;
        Reg.CloseKey;
      end;
  finally
    Reg.Free;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
  var Strings: TStringList;
      Count: Integer;
begin
  Strings := TStringList.Create;
  if GetMultiStringFromReg('Hardware\Description\System', 'SystemBiosVersion', Strings) then
    for Count := 0 to Strings.Count - 1 do
      ShowMessage(Strings[Count]);
end;


0
 

Author Comment

by:Llysander
ID: 1349731
Testing Philipleighs example.
Did a quick eye scan through the code, looks good, havn't had a chance to implement it yet.

Philip, if you would please post it as an answer so I can get it off the waiting answer list.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 1349732
Oke looks good, but I've implemented this with the valuenames in the project I talked about. It loads all the subkey values into a listbox. So if you would still take a look at it let me know.

Greetz
Bruintje
0
 
LVL 3

Accepted Solution

by:
philipleighs earned 50 total points
ID: 1349733
See my comment above.

Cheers,
Phil.

0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month10 days, 4 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question