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

REGISTRY KEYS

Status
Not open for further replies.

hbez

Instructor
Mar 25, 2003
49
ZA
I successfully create a new key and write a value to it. I cannot get to delete the values or the key itself. My code is
<code>
with TRegistry.Create do
try
Val := TStringList.Create;
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey('SOFTWARE\VotAfr\', True) then
begin
GetValueNames(Val);
for i := 0 to Val.Count-1 do
DeleteKey(ReadString('VotAfr'));
end
else
ShowMessage('Error opening key');
finally
Free;
Val.Free;
end;
</code>
This code runs withot errors and the value/s read are also correct - but it does not ger deleted. Someone pse tell me why?

Hannes
 
The following code creates or deletes a value in run.
And it works at least under XP, don't know about Vista/7 that might a your problem. [Don't write to HKLM and all that]

But looking at your code, aren't you trying to delete the entire 'Key' using the values names?
Shouldn't you be deleting the values with deletevalue(), then the delete the key 'VotAfr' with deletekey()

Obviously my code doesn't attempt to delete the 'run' key!

Code:
procedure TForm1.SetRegistryValue(Run: boolean);
var
  Reg: TRegistry;
begin
   Reg := TRegistry.Create;

  try
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run', True) then
       begin
          if Run then
             begin
               if not Reg.ValueExists('Countdown') then
                  begin
                     Reg.WriteString('Countdown','"C:\Delphi Projects\countdown\CountdownProj.exe"');
                  end

             end
          else
             begin
               if Reg.ValueExists('Countdown') then
                  begin
                    Reg.DeleteValue('Countdown');
                  end

             end;
          Reg.CloseKey;
       end
   finally
      Reg.Free;
   end;
end;

Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
BTW: I can confirm that Vista dosnt like my codes attempt to write to HKLM 'Run' key (for reasons given elsewhere) so dont do it.

Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
 
Tried EraseValue, same problem. This is on Win7 64bit. Will check it out on XP today.

Hannes
 
this is normal behaviour.
only elevated processes have full control over the registry.

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top