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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading the Registry Value Data

Status
Not open for further replies.

CarrahaG

Programmer
Mar 25, 2007
98
AW
Hello

We know how to read the value data of a registry value name? Also how can we check if the registry value data exists?

For example, the Registry Key'My Computer\HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI\ODBC Data Sources' has Value Names and Value Data as follows:

Value Name Value Data
----------------------- -------------------------------
CRSS SQL Server
Xtreme Sample Database Microsoft Access Driver (*.mdb)

How can we retrieve the Value Data of Value Name "CRSS"? Or how can we check for the existense of Value Data "Microsoft Access Driver (*.mdb)"?

Regards,
Georges
 
Don't really know what you mean by the data, this standard method of access in registry keys write the 'data' not the name.

Code:
  FInifile := TRegIniFile.Create('Software');
   with FIniFile do
     begin
        WriteBool(SECTION,'First',FirstRun);
        WriteString(SECTION,'Bus File', Statusbar.Panels[1].Text);
        WriteInteger(SECTION,'Timer Interval',Timer.Interval);
  free
end;

There are slightly more advanced methods for particular data types that are not covered by the basic functions.
Look at TRegistry rather than TRegIni level.
WriteDate is one of these, but there are lots of others that allow you to test for data sizes etc.


e.g for dates
Code:
  FIniFile := TRegIniFile.Create('Software');
   with Finifile do
   begin
      RootKey := HKEY_CURRENT_USER;
      openkey('\Software\Appname\'+ KeyName +'\'+ KeyName + 'DI', True);
      WriteDate(KeyName, SDate);
      closekey;
      free;
   end;



Steve [The sane]: Delphi a feersum engin indeed.
 
Hi Steve

Thanks for the reply. What I mean is that when you enter RegEdit, it is divided into 2 Window Panes (a left and a right one). On the left side are the Keys and on the right side is a list of Value Names and Data associated with that Key. What I want to accomplish is the ability to be able to (1) check for the existence of a Value Name and/or Value Data and (2) be able to read the Value Data of a Value Name.

For example, if you go to the registry key 'My Computer\HKEY_LOCAL_MACHINE\Software\Borland\Database Engine\Settings\DRIVERS\INTRBASE\DB OPEN' you will see on the right side of the Registry Editor the list of Value Names and Value Data associated with that key. "USER NAME" is a Value Name and "MYNAME" is the data for that name. This is actually from my Registry.

The following code does not work the way I desire it to work:

mystring := 'My Computer\HKEY_LOCAL_MACHINE\Software\Borland\Database Engine\Settings\DRIVERS\INTRBASE\DB OPEN\USER NAME';
keyexists := myRegistry.ValueExists(mystring);
mystring2 := myRegistry.ReadString(mystring);

keyexists does not equal "true" nor does mystring2 equal "MYNAME".

I hope I was a bit clearer.

Regards,
Georges




 
you want code like this:
Code:
[navy][i]// for automatic syntax highlighting see faq102-6487 
[/i][/navy][b]uses[/b]
  Registry, Windows;

[b]procedure[/b] GetRegistryVars;
[b]const[/b]
  MyKey = [teal]'\Software\Borland\Database Engine\Settings\DRIVERS\INTRBASE\DB OPEN'[/teal];
[b]var[/b]
  MyString2 : String;
[b]begin[/b]
  [b]with[/b] TRegistry.Create [b]do[/b]
    [b]try[/b]
      RootKey := HKEY_LOCAL_MACHINE;
      [b]if[/b] OpenKey(MyKey, False) [b]then[/b]
      [b]begin[/b]
        MyString2 := ReadString([teal]'USER NAME'[/teal]);
        CloseKey;
      [b]end[/b];
    [b]finally[/b]
      Free;
    [b]end[/b];
[b]end[/b];

 
Hi

This did exactly what I wanted. Thanks alot.

Regards,
Georges
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top