Solved

get class string of registry key

Posted on 2001-07-28
9
619 Views
Last Modified: 2011-09-20
How can i get the classname of a registry key?

just like this:

var
 openkeyhandle : hkey;
 classname     : string;

begin
 RegOpenKeyEx(HKEY_LOCAL_MACHINE, PChar('reg_subkey'), 0,KEY_ALL_ACCESS, OpenKeyHandle);
 
 classname := getClassname(openKeyHandle);

 regclosekey(openkeyhandle);

end;

I've tried RegQueryInfoKey and RegEnumKeyEx but
i couldn't get the classname:

var
 openkeyhandle : hkey;
 ClassName : array of char;
 classnameLength : Cardinal;

begin
 RegOpenKeyEx(HKEY_LOCAL_MACHINE, PChar('reg_subkey'), 0,KEY_ALL_ACCESS, OpenKeyHandle);
 
 SetLEngth(ClassName, 255);
 ClassNameLength := Length(ClassName);

RegQueryInfoKey (OpenKeyHandle, PCHAR(ClassName), @ClassNameLength,
                 NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);

 SetLEngth(ClassName, 0);

 regclosekey(openkeyhandle);
end;

I hope anybody can help me!!!
Bug





0
Comment
Question by:bugroger
  • 4
  • 3
  • 2
9 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 6329864
hi,
er registry keys dont have classnames ?
they are just strings or dwords etc..

what information exactly are you trying to get ?
0
 
LVL 2

Author Comment

by:bugroger
ID: 6329885

i want to get the registry path form a HKEY.
ex.:
 
RegOpenKeyEx(HKEY_LOCAL_MACHINE, PChar('Software\Microsoft'), 0,KEY_ALL_ACCESS, OpenKeyHandle);
 s := getClassName(OpenKeyHandle);  

 -> s = 'HKEY_LOCAL_MACHINE\Software\Microsoft'


0
 
LVL 2

Author Comment

by:bugroger
ID: 6329890
I think i have chosen the wrong expression.
I mean "Class String".

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 20

Expert Comment

by:Madshi
ID: 6329911
Hi Barry, look at the documentation about RegEnumKeyEx, there you'll find that there is really something like a class name for each registry key. But only in NT based systems. And it's not what Bug meant. Just wanted to mention that, because you said, there would be no class names in the registry...   :-)

Bug, what you want is not possible by using documented APIs, I'm sorry...   :-(

Regards, Madshi.
0
 
LVL 17

Expert Comment

by:inthe
ID: 6330117
mmm yep i see what you mean and should be returned in second param of RegQueryInfoKey as you have done above but none of my tests worked.
i know RegQueryInfoKey was working cause i used all the values instead of nil's and could get all other infos like amount of subkeys and amount of values etc but no class string .maybe it just dont work,i dont see any point in needing it or any code in other language that works either (doesnt work in vc++ either).
0
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 6330148
ahh got it :-)

the key needs to be actually created with the class string .
usually it is ignored therefore majority of keys done have it,i havent found one that has one except my test ones..

below ive done example ,create a key with a class string and then you can read it anytime later using pretty much your code from above:


type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  TempKeyStr : pchar = 'Software\BarryTest';
  TempKey : HKey;
  ClassStr : array[0..254] of char;

 implementation

{$R *.DFM}

uses registry;

procedure TForm1.Button1Click(Sender: TObject);
var
r : tregistry;
begin
r := tregistry.create;
with r do try
rootkey := HKEY_LOCAL_MACHINE;
begin
RegCreateKeyEx(rootkey,TempKeyStr, 0 ,pchar('test'),
REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,nil,TempKey,nil);
end;
finally
r.closekey;
end;
r.free;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
r : tregistry;
OpenKeyHandle : HKEY;
classStrLength : Cardinal;
begin
classStr := '';
r := tregistry.create;
with r do try
rootkey := HKEY_LOCAL_MACHINE;
begin
RegOpenKeyEx(rootkey,TempKeyStr,0,KEY_ALL_ACCESS,OpenKeyHandle);
ClassStrLength := Length(ClassStr);
RegQueryInfoKey(OpenKeyHandle,ClassStr, @ClassStrLength,
                NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL);
end;
finally
r.closekey;
end;
r.free;
showmessage(classStr);
end;


so basically the problem is not with your code its just because the keys were never created with a class string.

Regards Barry
0
 
LVL 2

Author Comment

by:bugroger
ID: 6330299
Sorry, but your code does not work Barry.
I think, like Madshi said,
 it only works "in NT based systems".

And it's not really what i want.

But you have answered "this" question and so
you will get the points :-)


Madshi,
 you will get some points too!
 Look at Question "Points for Madshi"


Thanks,
 Bug


 
0
 
LVL 17

Expert Comment

by:inthe
ID: 6330322
thanks,i am using win2k so the code works fine for me.

says in the help file about differences for nt and win95,the return handles have difference results on each if they are invalid etc..
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6330373
Hi Barry, Bug wanted to have the key name from the key handle. He was talking about the "class name" but didn't mean it.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 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