Solved

get class string of registry key

Posted on 2001-07-28
9
603 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now