How to avoid confirmation message when executing a .reg file with shellexecute command

Use the /s command-line switch. (see http://support.microsoft.com/kb/82821)


It's possible. Two methods are:

  1. %windir%\system32\regedit.exe /s file.reg
  2. %windir%\system32\reg.exe import file.reg

Either will silently import file.reg into the registry.


try this for importing the *.reg file,

  procedure ImportRegistry;
       var
        strProgram :String ;
        strCommand :String ;
        fileOne   :String ;
      begin

fileOne:=ExtractFilePath(Application.ExeName)+  'my_Resources\Default.reg';
strProgram := 'REGEDIT' ;
strProgram := strProgram + #0 ;
strCommand := '/SC /C ' + ExtractShortPathName(fileOne) ;
strCommand := strCommand + #0 ;

if ShellExecute(0,nil,@strProgram[1],@strCommand[1],nil,SW_HIDE) <= 32 then
  begin
        ShowMessage(SysErrorMessage(GetLastError)) ; //if there is any error in importing
  end;


end;

Also you can try this link unitEXRegistry.pas

This unitEXRegistry.pas unit has very useful functions to export registry file and also import silently the exported *.reg file

       procedure exportREgis;
        var
         texpr : TExRegistry;
        begin
         texpr:=TExRegistry.Create;
         texpr.RootKey:=HKEY_CURRENT_USER;
         texpr.OpenKeyReadOnly('\MyKey');
         texpr.ExportKey (ExtractFilePath(Application.ExeName)+'ExportedReg.reg');
         texpr.Free; 
       end;

Then to import you can use(silently)

     procedure TForm1.Button1Click(Sender: TObject);
        var
         texpr : TExRegistry;
        begin
          texpr:=TExRegistry.Create;
          texpr.ImportRegFile('c:\myReg.reg');
          texpr.Free;
       end;