Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

OpenKey/OpenKeyReadOnly only works sometimes

Posted on 2009-04-24
5
Medium Priority
?
2,169 Views
Last Modified: 2013-11-22
I'm being frustrated by this problem.

Connecting to remote registry using RegistryConnect, I'm able to open one key and read a value, but not another key.  The code for both is the same, same root, only the key name changes.

The really odd thing is, if I fire up RegEdit and connect remotely to the users' PC, I able to easily browse to either key and see their contents and values.  I'm not changing the root, nor is the authentication different.  I've tried using the same instance of TRegistry to read both, and then tried one for the first, then free it, then another one for the 2nd, and then free it.  Either way, same result: I could read the first key, but not the second, even though I could RegEdit to either one.  I've triple-checked the spelling of the key, and it's identical to the one I copy from RegEdit.

Anyone have any ideas as to what I can try next?

(The code will display the logon name, but will fail when trying to get 'Enabled'.)
procedure TForm1.Button1Click(Sender: TObject);
var RegFile : TRegistry;
    connected, r1, r2 : boolean;
    lun : string;
    enabled : integer;
begin
// partial code:
 
RegFile := TRegistry.Create;
RegFile.RootKey := HKEY_USERS;
connected := RegFile.RegistryConnect('\\hou-l0-kpeterso');
if connected then
  begin
     r1 := RegFile.OpenKeyReadOnly('S-1-5-21-1715567821-484763869-839522115-98312\Software\Microsoft\Windows\CurrentVersion\Explorer');
     lun := RegFile.ReadString('Logon User Name');
     if not r1 then ShowMessage('first OpenKeyReadOnly failed')
       else ShowMessage('Logon User Name: '+lun);
     r2 := RegFile.OpenKeyReadOnly('S-1-5-21-1715567821-484763869-839522115-98312\Software\America Online\AOL Instant Messenger (TM)\CurrentVersion\Proxy');
     if not r2 then ShowMessage('first OpenKeyReadOnly failed')
       else
         begin
             enabled := RegFile.ReadInteger('Enabled');
             ShowMessage('Enabled = '+IntToStr(enabled));
         end;
 end
else ShowMessage('not connected');
 
end;

Open in new window

0
Comment
Question by:rlaird
  • 3
  • 2
5 Comments
 
LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 750 total points
ID: 24230808
is this all 32 bit or a mix 64 bit - 32 bit ?

you need to put some checks in to see if it opens and a key all access
don't you get an AV when trying to read a non opened key ?
procedure TForm1.Button1Click(Sender: TObject);
var RegFile : TRegistry;
    connected, r1, r2 : boolean;
    lun : string;
    enabled : integer;
begin
// partial code:
  RegFile := TRegistry.Create(KEY_ALL_ACCESS);
  try
    RegFile.RootKey := HKEY_USERS;
    connected := RegFile.RegistryConnect('\\hou-l0-kpeterso');
    if connected then
    begin
      r1 := RegFile.OpenKeyReadOnly('S-1-5-21-1715567821-484763869-839522115-98312\Software\Microsoft\Windows\CurrentVersion\Explorer');
      if not r1 then 
        ShowMessage('first OpenKeyReadOnly failed')
      else 
      begin
        lun := RegFile.ReadString('Logon User Name');
        ShowMessage('Logon User Name: '+lun);
      end;
      r2 := RegFile.OpenKeyReadOnly('S-1-5-21-1715567821-484763869-839522115-98312\Software\America Online\AOL Instant Messenger (TM)\CurrentVersion\Proxy');
      if not r2 then 
        ShowMessage('second OpenKeyReadOnly failed')
      else
      begin
        enabled := RegFile.ReadInteger('Enabled');
        ShowMessage('Enabled = '+IntToStr(enabled));
      end;
    end else 
      ShowMessage('not connected');
  finally
    FreeAndNil(RegFile);
  end;
end;

Open in new window

0
 

Author Comment

by:rlaird
ID: 24230817
This is all 32-bit, D2007.  I don't try to read a value in a key if the key doesn't open.   But I'll try your code and see if it helps (on Monday).  Thanks!
0
 

Author Comment

by:rlaird
ID: 24260045
Ok, I tried your code but the result was the same as my code.  I'm getting the strong feeling that it has more to do with Windows authentication than my code.  You would *think* that, if I can get to it via RegEdit, then, on the same machine, same user, same login that I'm running RedEdit on, that the code I'd run would have the same access, but maybe that assumption is false?

So, I tried the old trick of using an WNetConnection of the IPC on the destination machine to give me greather authority level, but that didn't work either.

Anyone have any ideas of where I go from here?  BTW, 80%-95% of the machines I try this code on works... but there are some of the machines that give the wacky result I've been discussing.  So, I think it's definitely not the code.  Still, it's VERY frustrating, especially when I can manually use RegEdit to see the key values.
0
 
LVL 38

Accepted Solution

by:
Geert Gruwez earned 750 total points
ID: 24260160
The windows authentication has certainly got it's finger in this !
I got the same problem, but i had a server which had access to all accounts and pc's and ran it from there.

That solved it for me ...
0
 

Author Closing Comment

by:rlaird
ID: 31574352
I'm going to assume this is not really a Delphi issue, but a Windows authentication issue.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
Screencast - Getting to Know the Pipeline
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

581 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