Inno setup 如何在inno脚本中传递ini脚本和exe设置

Inno setup 如何在inno脚本中传递ini脚本和exe设置,inno-setup,ini,pascalscript,Inno Setup,Ini,Pascalscript,我必须进行静默安装,这就是我使用inno脚本的原因。 我使用ini文件获取额外信息,并调用RunProcess()方法将此ini文件作为参数传递。首先,我提取安装程序和ini文件,然后调用Runprocess()方法,如下所示: procedure InstallNetTime(); Forward; procedure CreateNTPRegistryEntries(); Forward; procedure InstallNetTime(); begin

我必须进行静默安装,这就是我使用inno脚本的原因。 我使用ini文件获取额外信息,并调用
RunProcess()
方法将此ini文件作为参数传递。首先,我提取安装程序和ini文件,然后调用
Runprocess()
方法,如下所示:

procedure InstallNetTime(); Forward;   
procedure CreateNTPRegistryEntries(); Forward;        


procedure InstallNetTime();  
begin   

    if RegKeyExists(HKEY_LOCAL_MACHINE_32,'SOFTWARE\MICROSOFT\Windows\CurrentVersion\Uninstall\NetTime_is1') then  
    begin         
       exit;  
    end;

    ShowStatusMessage('Installing NetTime...');     
    CreateNTPRegistryEntries();   
    ExtractTemporaryFile('NetTime-2b7.exe');   
    RunProcess('{tmp}\NetTime-2b7.exe', '');    
 end;

procedure CreateNTPRegistryEntries();     
begin      
     RegDeleteKeyIncludingSubkeys ( HKEY_LOCAL_MACHINE_32, 'SOFTWARE\Subjective            Software\NetTime');  
     RegWriteStringValue(HKEY_LOCAL_MACHINE_32, 'SOFTWARE\Subjective
 Software\NetTime', 'Hostname', '127.0.0.1');      
     RegWriteDWordValue(HKEY_LOCAL_MACHINE_32, 'SOFTWARE\Subjective
 Software\NetTime', 'Protocol', 2);  
     RegWriteDWordValue(HKEY_LOCAL_MACHINE_32, 'SOFTWARE\Subjective
 Software\NetTime', 'Port', 37);  
     RegWriteDWordValue(HKEY_LOCAL_MACHINE_32, 'SOFTWARE\Subjective
 Software\NetTime', 'SyncFreq', 600);      
     RegWriteDWordValue(HKEY_LOCAL_MACHINE_32, 'SOFTWARE\Subjective
 Software\NetTime', 'LostSync', 7500);  
     RegWriteDWordValue(HKEY_LOCAL_MACHINE_32, 'SOFTWARE\Subjective
 Software\NetTime', 'WarnAdj', 120);  
     RegWriteDWordValue(HKEY_LOCAL_MACHINE_32, 'SOFTWARE\Subjective
 Software\NetTime', 'Retry', 600);      
     RegWriteDWordValue(HKEY_LOCAL_MACHINE_32, 'SOFTWARE\Subjective
 Software\NetTime', 'Server', 1);   
 end;
第二行和第三行正在执行,因为我可以看到注册表中的设置条目。但是
RunProcess()
方法在这里不起作用。安装程序只是跳过这一步。我不太清楚如何将参数和exe文件一起传递,因为我不熟悉Inno脚本,并且在上面找不到足够的文档。请帮助我了解如何使用
RunProcess()
方法。或者如何使用
RunProcess()
方法进行静默安装。

Inno安装程序中不存在
RunProcess()
函数(默认情况下),除非您自己创建它

您可以通过使用来解决这个问题

第一个参数是要执行的文件。第二个参数是要传递给它的参数

ExtractTemporaryFile('ntp-setup-win32.exe');
ExtractTemporaryFile('MeinBergNTP.ini');
RunProcess('msiexec', AddQuotes(ExpandConstant('{tmp}\ntp-setup-win32.exe')) 
  + AddQuotes(ExpandConstant('{tmp}\MeinBergNTP.ini'))
  + ' /quiet /norestart'); 


谢谢你的回复。但我需要使用RunProcess(),因为所有其他iss文件都只使用此方法。使用exec()方法时,它工作正常:)

您可以编写一个包装器函数

RunProcess()

围绕
Exec()
构建一个包装函数
RunProcess()
,该函数接受可执行文件及其参数

var
  ResultCode: Integer;
begin
  // Launch installer and wait for it to terminate
  if Exec(ExpandConstant('{tmp}\ntp-setup-win32.exe'),
          ExpandConstant('{tmp}\MeinBergNTP.ini') + ' /quiet /norestart',
          '', SW_SHOW,ewWaitUntilTerminated, ResultCode) then
  begin
    // handle success
  end 
  else begin
    // handle failure
  end;
end;
用法:

function RunProcess(Executable: String, Parameters: String): Integer;
var 
    ResultCode: Integer;
begin
    Exec( ExpandConstant(Exectuable),
          ExpandConstant(Parameters),
         '', SW_SHOW,ewWaitUntilTerminated, ResultCode);
    Result := ResultCode;
end;
RunProcessHidden()

嗯,有很多方法可以隐藏执行官:

  • 您可以尝试将
    Exec()
    函数的ShowCmd参数值切换为
    SW\u HIDE
  • 或者您可以通过
    start/b…
    调用可执行文件。检查
    start/?
    以了解其选项
  • 或者您也可以在安装程序中插入一个小的帮助工具,如
    RunHiddenConsole.exe
    HideExec.exe
    ,然后通过该工具调用可执行文件

  • 包括辅助工具

    RunProcess('{tmp}\ntp-setup-win32.exe', '{tmp}\MeinBergNTP.ini /quiet /norestart');
    
  • 提取

    [Files]
    Source: RunHiddenConsole.exe; DestDir: {tmp}; Flags: dontcopy
    
  • 添加包装函数RunProcessHidden()以使用命令参数调用工具

    // extract unzip util from the compressed setup to temp folder and define a shortcut
    ExtractTemporaryFile('RunHiddenConsole.exe');
    hideConsole := ExpandConstant('{tmp}\RunHiddenConsole.exe');
    

Inno设置中没有
RunProcess
功能。如果它是您的用户定义函数,我们需要查看其代码以帮助您。无论如何,您为什么要使用
msiexec
运行
.exe
文件?
msiexec
用于运行
.msi
文件。您应该直接运行
.exe
。这是我使用RunProcess()方法安装exe安装程序时使用的代码,它工作正常,没有任何参数。它不是用户定义的。我检查了所有相关的iss文件,它们都使用RunProcess()或RunProcessHidden()类函数,这些函数不是用户定义的。我需要将ini文件作为参数调用RunProcess()。不,IS中没有
RunProcess
函数。它必须是用户定义的。另外,您的新代码
RunProcess
调用与您发布的第一个代码不同。投票结束你的问题,因为不清楚。谢谢你的回复。但我需要使用RunProcess(),因为所有其他iss文件都只使用此方法。使用exec()方法工作正常:)。我更新了答案,并将包装函数的示例添加到
exec()
。我使用的是TmpFileName1:=ExpandConstant({tmp}')+'\ntp-setup-win32.exe';TmpFileName2:=ExpandConstant('{tmp}')+'\MeinBergNTP.ini';Cmd2:=TmpFileName1+'/USEFILE='+TmpFileName2;Exec('cmd.exe','/S'+Cmd2',SW_HIDE,ewwaitunfiltered,ResultCode);工作正常。正如它调用cmd并安装安装程序一样。但是在RunProcess()中,它不是静默地执行,而是打开一个命令提示符。/S可能是setup exe的静默模式开关,组合了mit SW_HIDE。很高兴你解决了!如何在RunProcess方法中传递这些参数。静默安装的As命令是:ntp-setup-win32.exe/USEFILE=C:\MeinBergNTP.ini
// Run an external command via RunHiddenConsole
function RunProcessHidden(Command: String): Integer;
var
    ErrorCode: Integer;
begin
   if Exec(hideConsole, ExpandConstant(Command), '', SW_SHOW, ewWaitUntilTerminated, ErrorCode) then
   begin
       Result := ErrorCode;
   end
   else
   begin
      Log('[Error] ExecHidden failed executing the following command: [' + ExpandConstant(Command) + ']');
      Result := ErrorCode;
   end;
end;