TRegistry cannot open existing key

We are checking in code for a registered pdf reader before we try to open a pdf file.  

However, we are having problems on some machines that do not seem to be able to open the .pdf key in HKEY_CLASSES_ROOT, despite it being there in the registry and return false from the PdfRegistered function.

  if PdfRegistered then
    ShellExecute(0, nil, pchar(pdfFile), nil, nil, SW_SHOWNORMAL)
  else
    AskInstallAcrobat;

function TfrmMain.PdfRegistered: boolean;
begin
  with TRegistry.Create do
  try
    RootKey := HKEY_CLASSES_ROOT;
    Result := OpenKey('.pdf', False);  // False = do not create
  finally
    Free;
  end;
end;

Open in new window


Any ideas
rogerfg7Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
jimyXConnect With a Mentor Commented:
If you do not want to change the code (or changing the code is not possible at this stage) then you are left with one option which is, start your application with "RUN AS" and select Admin account.
0
 
jimyXCommented:
Do you have administrator rights in those machines?
0
 
rogerfg7Author Commented:
No. These are user machines.  This is a searchable CD that goes out to customers.  We have had this problem recently on a few machines, both in-house and out on customers' sites.
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
jimyXCommented:
You can try either:
TRegistry.Create(KEY_QUERY_VALUE);

Open as read only:
Reg.OpenKeyReadOnly();

Or:
Reg.Access := KEY_READ;
0
 
rogerfg7Author Commented:
Can anything be done without changing the code base?
0
 
jimyXCommented:
I am afraid you are going to need Admin Rights to access that.
0
 
jimyXCommented:
BTW, what OS is that?
0
 
rogerfg7Author Commented:
Thanks for changing the zone, I hit submit from the preview screen, without selecting the right zone.

OS I have tested on have all been XP Prof.

Can we get the administrator to enable the .pdf key in the registry to be readable by the code when logged in as non-admin user?
0
 
rogerfg7Author Commented:
Many thanks.  We will change the code base for the next release and test on a few PCs prior to release.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.