jimsweb
jimsweb

Reputation: 1082

writing to HKLM with admin privilege

I am running my delphi application using 'run as admin..' by right clicking on the exe. This application has following code to insert into HKLM registry.

begin
    kValue := 'testing';
    Reg.CloseKey;
    Reg.Free;
    try
      Reg := TRegistry.Create(KEY_READ OR KEY_WOW64_64KEY);
      Reg.RootKey := HKEY_LOCAL_MACHINE;
      Reg.OpenKey('SOFTWARE\explorev2', True);
      Reg.WriteString('test', kValue);
      Result := Reg.ReadString('test');
    except
      ;
    end;

I am getting exception 'failed to set data for 'test''; though the application is running with admin privileges. Can anybody help me out..?

Upvotes: 0

Views: 1172

Answers (1)

Chris
Chris

Reputation: 3121

You are creating the TRegistry object with read access only:

Reg := TRegistry.Create(KEY_READ OR KEY_WOW64_64KEY);

Create it with write access instead:

Reg := TRegistry.Create(KEY_WRITE or KEY_WOW64_64KEY);

Upvotes: 6

Related Questions