Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

get class string of registry key

Posted on 2001-07-28
9
Medium Priority
?
638 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
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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

610 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