?
Solved

get class string of registry key

Posted on 2001-07-28
9
Medium Priority
?
629 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
[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
  • 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
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 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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month10 days, 3 hours left to enroll

762 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