Board index » cppbuilder » Registry Subkeys

Registry Subkeys


2004-06-12 02:56:14 AM
cppbuilder106
Hi
I was to know how can I reach a Registry Subkeys?
TRegistry *MyReg=new TRegistry();
MyReg->RootKey=HKEY_CURRENT_USER;
MyReg->OpenKey("Software",false);
... // here , how can I reach all subjeys names?
Thx
 
 

Re:Registry Subkeys

Am I fool dear friend?
I took a look but I got more confused !
Michel Leunen wrote in message < XXXX@XXXXX.COM >...
Quote
Babak wrote:

>TRegistry *MyReg=new TRegistry();
>MyReg->RootKey=HKEY_CURRENT_USER;
>MyReg->OpenKey("Software",false);
>... // here , how can I reach all subjeys names?

Take a look at TRegistry::HasSubKey(), TRegistry::GetKeyNames()

Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, C++BuilderX, BCC5.5.1 Web site:
www.leunen.com/
----------------------------------------
 

Re:Registry Subkeys

Babak wrote:
Quote
TRegistry *MyReg=new TRegistry();
MyReg->RootKey=HKEY_CURRENT_USER;
MyReg->OpenKey("Software",false);
... // here , how can I reach all subjeys names?
Take a look at TRegistry::HasSubKey(), TRegistry::GetKeyNames()
Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, C++BuilderX, BCC5.5.1 Web site:
www.leunen.com/
----------------------------------------
 

{smallsort}

Re:Registry Subkeys

"Babak" < XXXX@XXXXX.COM >wrote in message
Quote
I took a look but I got more confused !
What exactly are you having a problem with? What exactly ar you trying to
accomplish in the first place?
Gambit
 

Re:Registry Subkeys

Dear Gambit
I was thinking I exactly said what I mean but I try to say in another way.
I know how to Open/Create and Read/Write From/To Registry.
But Now I have a problem.
My Problem is when I was trying to read a range of Keys I dont know how !
For example Registry Address : HKEY_DYN_DATA\PerfStats
has 5 Keys (looks like folders) but when I'm in coding mode , I dont know
how many keys are there and what are their names? !
Then I need to Know their Key Names to Open.
Any help?
Am I clear now?
 

Re:Registry Subkeys

Babak wrote:
Quote
but when I'm in coding mode , I dont know
how many keys are there and what are their names? !
Yes, you know that.
TRegistry::GetKeyNames() returns a TStrings which is a list of strings.
Each string represents one subkey name. A TStrings has a count property
too which gives you how many subkeys your current key has.
Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, C++BuilderX, BCC5.5.1 Web site:
www.leunen.com/
----------------------------------------
 

Re:Registry Subkeys

Dear Gambit
I was thinking I exactly said what I mean but I try to say in another way.
I know how to Open/Create and Read/Write From/To Registry.
But Now I have a problem.
My Problem is when I was trying to read a range of Keys I dont know how !
For example Registry Address : HKEY_DYN_DATA\PerfStats
has 5 Keys (looks like folders) but when I'm in coding mode , I dont know
how many keys are there and what are their names? !
Then I need to Know their Key Names to Open.
Any help?
Am I clear now?
Remy Lebeau (TeamB) wrote in message <40cb6ec6$ XXXX@XXXXX.COM >...
Quote

"Babak" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>I took a look but I got more confused !

What exactly are you having a problem with? What exactly ar you trying to
accomplish in the first place?


Gambit


 

Re:Registry Subkeys

I was asking for a sample source code to study
my problem still persist.
Thats why I ask again and again
 

Re:Registry Subkeys

"Babak" < XXXX@XXXXX.COM >wrote in message
Quote
My Problem is when I was trying to read a range of Keys
I dont know how ! For example Registry Address :
HKEY_DYN_DATA\PerfStats has 5 Keys (looks like
folders) but when I'm in coding mode , I dont know how
many keys are there and what are their names? !
Michael already told you how to do that.
Gambit
 

Re:Registry Subkeys

What code is needed to get&set subkeys in the registry, like
HKEY_CURRENT_USER\Software\Company\Product\Settings\Key1
?
 

Re:Registry Subkeys

Can't you use TRegistry?
basic example:
TRegistry *Registry;
AnsiString somestring;
Registry = new TRegistry;
Registry->RootKey = HKEY_CURRENT_USER;
if(Registry->OpenKey("Software\Company\Product\Key1", false))
{
somestring = Registry->ReadString("somevalue");
Registry->WriteString("somevalue", somestring);
Registry->CloseKey();
}
delete Registry;
 

Re:Registry Subkeys

That part is simpler than I thought.
When there are more entries within \Product\, has each one to be opened
individually?
Richard Bradbrook wrote:
Quote
Can't you use TRegistry?

basic example:

TRegistry *Registry;
AnsiString somestring;

Registry = new TRegistry;
Registry->RootKey = HKEY_CURRENT_USER;
if(Registry->OpenKey("Software\Company\Product\Key1", false))
{
somestring = Registry->ReadString("somevalue");
Registry->WriteString("somevalue", somestring);
Registry->CloseKey();
}
delete Registry;


 

Re:Registry Subkeys

Quote
When there are more entries within \Product\, has each one to be opened
individually?
Yeah you'd have to use OpenKey for each branch.
Value wise, you just keep reading and writing the various bits you need to.
Maybe it would be possible for you to group your values (by using a name
prefix) rather than having to create several different keys?
Failing that, maybe it would indeed be easier for you to stick with the
WinAPI commands.
Just take a look in the help file, they're not tricky.
 

Re:Registry Subkeys

"Richard Bradbrook" < XXXX@XXXXX.COM >wrote in message
Quote
if(Registry->OpenKey("Software\Company\Product\Key1", false))
Don't forget that you need to double up on backslashes:
if( Registry->OpenKey("Software\\Company\\Product\\Key1", false) )
Quote
somestring = Registry->ReadString("somevalue");
Registry->WriteString("somevalue", somestring);
Also, do note that reading and writing to the same key can fail on NT-based
systems that have security turned on. You should never open a key for
read/write access. Open the key for read-only and write-only access
instead, ie:
TRegistry *Registry = new TRegistry;
try
{
Registry->RootKey = HKEY_CURRENT_USER;
AnsiString somestring;
Registry->Access = KEY_QUERY_VALUE;
if( Registry->OpenKey("Software\\Company\\Product\\Key1", false) )
{
somestring = Registry->ReadString("somevalue");
Registry->CloseKey();
}
Register->Access = KEY_SET_VALUE;
if( Registry->OpenKey("Software\\Company\\Product\\Key1", false) )
{
Registry->WriteString("somevalue", somestring);
Register->CloseKey();
}
}
__finally {
delete Registry;
}
Gambit