Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read/write the registry?

How to read/write the registry?

by  Ferran  Posted    (Edited  )
The best way to access to the registry is using TRegistry class.

TRegistry *Path;

Registry has "Keys" and "Values". Keys are "like" directories and Values are "like" files.
With TRegistry class you can access to one Key setting the "RootKey" and then Open
a key below it.

Path=new TRegistry;
Path->RootKey=HKEY_LOCAL_MACHINE; // Or other Root key
Path->OpenKey("\\Software\\MySoftware",true); // Open or create

Then, you can access to single "Values" by name. They can be BinaryData, Bool, Currency, Date, DateTime, Float, String, Integer and Time.

// To assure you have a value :
if (!Path->ValueExists("MyValue")){
Path->WriteInteger("MyValue",_DEFAUL_VALUE);
}

// To Read :
int Value;
Value=Path->ReadInteger("MyKey");
// or
String Value;
Value=Path->ReadString("MyKey");
...

// Write :
int Value;
Path->WriteInteger("MyKey",Value);
// or
String Value;
Path->WriteInteger("MyKey",Value);
...
delete Path;


Ferran Casarramona
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top