Registry Backup on win9x

Hi experts,

I have a problem, I found folow function to backup registry but doesn't work on Win9x this work fine on
win2k/winxp, the function is:

procedure TForm1.SaveKeyToFile(Key, _File: Pchar; _default:boolean);
const
  SE_BACKUP_NAME = 'SeBackupPrivilege';
  SE_RESTORE_NAME = 'SeRestorePrivilege';

var
  MainKey: HKey;
  TP, Prev: TTokenPrivileges;
  RetLength: DWORD;
  Token: THandle;
  LUID: TLargeInteger;
  x: integer;
  i: PDWORD;
begin

   x:=RegOpenKeyEx(HKEY_LOCAL_MACHINE, Key, 0, KEY_QUERY_VALUE, MainKey);
  if x = ERROR_SUCCESS then
  begin
    try
      // under WinNT/Win2K you need SE_BACKUP_NAME privilege to save and restore registry keys
      SetLastError(0);
      // enable backup privilege
      if OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, Token) then
      begin
        if LookupPrivilegeValue(nil, SE_BACKUP_NAME, LUID) then
        begin
          TP.PrivilegeCount := 1;
          TP.Privileges[0].Luid := LUID;
          TP.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
          if not AdjustTokenPrivileges(Token, False, TP, SizeOf(TTokenPrivileges), Prev, RetLength) then RaiseLastWin32Error;
          if FileExists(_File) then DeleteFile(_File);
          IF RegSaveKey(MainKey,_File, nil)= 0 THEN
             showmessage('OK ')
          else
             showmessage('Fallo backup. '+SystemErrorMessage(RegSaveKey(MainKey,_File, nil)));
          // Revoke all privileges this process holds (including backup)
          AdjustTokenPrivileges(Token, True, TP, 0, Prev, RetLength);

         // close handle to process token
         CloseHandle(Token);
        end;
      end
    finally
      RegCloseKey(MainKey);
    end;
  end


end;

procedure TForm1.Button1Click(Sender: TObject);
begin
         SaveKeyToFile(pchar('SOFTWARE'),pchar('C:\SOFTWARE'),false);
end;

Can any body helpme with howto backup registry on win9x with same function ?

Thanks in advance.

MauricioGaviriaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wim ten BrinkSelf-employed developerCommented:
In Win9x you don't need to use any security garbage, so you could discard the privileges-related stuff... This might be enough: (I can't test it though.)

procedure TForm1.SaveKeyToFile(Key, _File: Pchar; _default:boolean);
var
  MainKey: HKey;
  RetLength: DWORD;
  LUID: TLargeInteger;
  x: integer;
  i: PDWORD;
begin
   x:=RegOpenKeyEx(HKEY_LOCAL_MACHINE, Key, 0, KEY_QUERY_VALUE, MainKey);
  if x = ERROR_SUCCESS then
  begin
    try
      if FileExists(_File) then DeleteFile(_File);
      IF RegSaveKey(MainKey,_File, nil)= 0 THEN
         showmessage('OK ')
      else
         showmessage('Fallo backup. '+SystemErrorMessage(RegSaveKey(MainKey,_File, nil)));
    finally
      RegCloseKey(MainKey);
    end;
  end
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Wim ten BrinkSelf-employed developerCommented:
Should be:

var
  MainKey: HKey;
  x: integer;

The other variables aren't required. Still, I don't have any Win9x so I can't test this code...
0
MadshiCommented:
Alternatively in win9x you can simply copy the system.dat and user.dat files by using CopyFile, I believe.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

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.