Problem z zapisywaniem klucza

0

Mam problem z zapisywaniem klucza rejestru do pliku. [sciana]

procedure TForm1.Button1Click(Sender: TObject);
var REG : TRegistry;
begin
REG := TRegistry.Create;
REG.RootKey := HKEY_LOCAL_MACHINE;
REG.OpenKeyReadOnly('HARDWARE\Acpi');
REG.SaveKey('\', 'F:\Ser.reg');
REG.CloseKey;
REG.Free;
end;

Wszystko niby działa ale plik Ser.reg jest zupełnie pusty!
Przeszukałem forum i nic o tym nie znalazłem więc mam nadzieje że będziecie w stanie mi pomóc. (Kod jest tylko przykładem)

0
function SetPrivilege(Enabled:boolean):boolean;
var Priv: TTokenPrivileges;
    Token: THandle;
    Return: DWORD;
begin
result:=FALSE;
if not OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, Token) then
  exit;
try
  ZeroMemory(@Priv, sizeof(Priv));
  Priv.PrivilegeCount:=1;
  if Enabled then
    Priv.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;
  if not LookupPrivilegeValue(nil, 'SeBackUpPrivilege', Priv.Privileges[0].Luid) then
    exit;
  if not AdjustTokenPrivileges(Token, FALSE, Priv, 0, nil, Return) then
    exit;
  if (GetLastError()<>ERROR_SUCCESS) then
    exit;
finally
  CloseHandle(Token);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var Reg: TRegistry;
begin
SetPrivilege(TRUE);
Reg:=TRegistry.Create;
try
  Reg.RootKey:=HKEY_LOCAL_MACHINE;
  DeleteFile('c:\plik');
  if Reg.SaveKey('Software\Borland\Delphi', 'c:\plik') then
    ShowMessage('OK');
finally
  Reg.Free;
  end;
SetPrivilege(FALSE);
end;

Musisz grzecznie poprosić system o żeton, by skorzystać z przydzielonego przywileju tworzenia kopii zapasowej :]

0

FileName is the file into which to save the key information. It must be the name of a new file that does not already exist. On FAT file systems FileName cannot include an extension.

1 użytkowników online, w tym zalogowanych: 0, gości: 1