Solved

Registry Problem

Posted on 2002-04-05
8
168 Views
Last Modified: 2010-04-04
I have A problem with the following code. this code is not retrieving me the data. when i look at the path through regedit i can see the reg values r there. wheather i need to refresh  or what should i do


procedure TForm1.Button1Click(Sender: TObject);
var
  sRegSubKey : string;
  vRegistry : TRegistry;
  Version,databaseNameT : string;

begin
  try
    try
      sRegSubKey := 'Path to the reg file';
      vRegistry := TRegistry.Create;
      vRegistry.RootKey := HKEY_LOCAL_MACHINE;
      {surinscrit la registry si nécessaire, CanCreate=True}
      vRegistry.OpenKey(sRegSubKey, True);
      with vRegistry do
      begin
        Version := ReadString('Version');
        databaseNameT:=ReadString('DatabaseName');
      end; {with}

    finally
     vRegistry.free;
    end;

    Label1.Caption := 'Release '+Version;
    Label2.Caption:='DatbaseName '+databaseNameT;
  except
    On E:Exception do
    begin
      ShowMessage('excep');
    end;
  end;
end;
0
Comment
Question by:jonathan2002
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 4

Expert Comment

by:nestorua
ID: 6922525
HI,jonathan2002,
You are not allowed to create Key as you want.
What you can do is:
sRegSubKey := 'SoftWare\Path to the reg file';
...
or
sRegSubKey := 'SoftWare\Path to the reg file';
...
vRegistry.RootKey := HKEY_CURRENT_USER;
...
And one more remark.
You use the block try-finally-end in not quite proper way.
Sincerely,
Nestorua.
0
 
LVL 4

Expert Comment

by:nestorua
ID: 6922528
Sorry,
In the second way it is:
or
sRegSubKey := 'Path to the reg file';
...
vRegistry.RootKey := HKEY_CURRENT_USER;Sincerely,
Nestorua.
0
 
LVL 1

Accepted Solution

by:
OryxConLara earned 25 total points
ID: 6923533
jonahat2002--

I'll assume that when you wrote "'Path to the reg file'" you meant something like "SOFTWARE\Borland\Borland Shared\DBExpress", and just didn't want to bother us with the details :).

One problem may be that the Version and Databasename keys aren't strings, but some other type. What type of key does Regedit show for these two values of the key? If it's not REG_SZ, then these aren't stored as strings, and we'll have to do something else to extract this info. If you can tell me what kind they are, I think I may be able to help you further.
0
 
LVL 17

Assisted Solution

by:geobul
geobul earned 25 total points
ID: 6923715
Hi,

try:
vRegistry.Access := KEY_READ;
vRegistry.OpenKey(sRegSubKey, false);

perhaps you have 'read only' access to that key.

Regards, Geo
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 2

Expert Comment

by:gallaghe
ID: 6928247
You should first check to see if the key exists, then open it Read-Only if under HKLM i.e.

   if vRegistry.OpenKey(sRegSubKey, False) then
   begin
      ...
   or

   if vRegistry.OpenKeyReadOnly(sRegSubKey) then
   begin
      ...


Also when getting a value use
   if vRegistry.ValueExists(sRegSubKey) then
      Version := ReadString('Version');
      ...

never assume the value exists.
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9002927
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Split between OryxConLara and gallaghe

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0
 
LVL 17

Expert Comment

by:geobul
ID: 9003078
pnh73,

what new have gallaghe added to this question? There are two possible reasons: either the key is not of string type (pointed out by OryxConLara) or the user has no write access and has to open the key read-only (pointed by me). The original code has try..except block so it's definatelly not necessary to check if the key exists beforehand.

Regards, Geo
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9004732
I will leave a recommendation in the Cleanup topic area that this question is:

Split between OryxConLara and geobul

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Paul (pnh73)
EE Cleanup Volunteer
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now