Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Multi String Registry Type

Posted on 1998-12-07
13
Medium Priority
?
586 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 200 total points
ID: 1349733
See my comment above.

Cheers,
Phil.

0

Featured Post

[Webinar] Protection from Cyberattacks

In this session, we’ll dive into the complexities of modern cyber threats and why only multi-vector protection can keep today’s businesses secure through the various stages of a cyberattack, across multiple vectors. Thursday September 14, 2017 10:00 A.M. PDT

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

730 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