在我的程序中,我在启动时检查一个注册表键,如果它不存在,我就用ShellExecute命令执行位于应用程序文件夹中的reg文件。我怎样才能避免在执行这个命令时收到confimation信息。有什么方法可以做到这一点,还是因为安全原因,这是不可能的?
使用s命令行开关。(参见 http:/support.microsoft.comkb82821)
是可以的。 两个方法是:
两者都会默默地将file.reg导入注册表。
试试这个导入*.reg文件。
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;
你也可以试试这个链接 unitEX注册表.pas
这个单元EXRegistry.pas具有非常有用的功能,可以导出注册表文件,也可以静静地导入导出的*.reg文件。
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;
然后你可以使用(默默地)导入。
procedure TForm1.Button1Click(Sender: TObject);
var
texpr : TExRegistry;
begin
texpr:=TExRegistry.Create;
texpr.ImportRegFile('c:\myReg.reg');
texpr.Free;
end;