【问题标题】:How to pass a ini script and a exe setup in inno script如何在 inno 脚本中传递 ini 脚本和 exe 设置
【发布时间】:2015-10-16 11:47:35
【问题描述】:
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;

我必须进行静默安装,这就是我使用 inno 脚本的原因。 我正在使用 ini 文件获取额外信息,并调用 RunProcess() 方法将此 ini 文件作为参数传递。首先,我提取 setup 和 ini 文件,然后调用 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() 方法在这里不起作用。安装程序只是跳过这一步。我不太清楚如何将参数和 exe 文件一起传递,因为我是 Inno Scripts 的新手,并且在上面找不到足够的文档。请帮我看看我应该如何使用RunProcess() 方法。或者如何使用RunProcess() 方法进行静默安装。

【问题讨论】:

  • Inno Setup 中没有 RunProcess 函数。如果是你自定义的函数,我们需要查看它的代码来帮助你。
  • 无论如何,你为什么使用msiexec 来运行.exe 文件? msiexec 用于运行 .msi 文件。你应该直接运行.exe
  • 这是我用于使用 RunProcess() 方法安装 exe 设置的代码,它在没有任何参数的情况下工作正常。它不是用户定义的。我检查了所有相关的 iss 文件,它们都使用 RunProcess() 或 RunProcessHidden() 类型的函数,这些不是用户定义的。我需要调用 RunProcess() 将 ini 文件作为参数传递。
  • 不,IS 中没有RunProcess 函数。它必须是用户定义的。此外,您的新代码 RunProcess 调用与您发布的第一个代码不同。投票结束您的问题不清楚。

标签: inno-setup ini pascalscript


【解决方案1】:

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

您可以使用Exec 解决问题。

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

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;

感谢您的回复。但我需要使用 RunProcess() 因为所有其他 iss 文件都只使用这种方法。使用 exec() 方法虽然可以正常工作:)。

你可以写一个包装函数。

RunProcess()

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

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

用法:

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

RunProcessHidden()

嗯,有很多方法可以隐藏 exec:

  • 您可以尝试将 Exec() 函数的 ShowCmd 参数的值切换为 SW_HIDE
  • 或者您可以通过start /b ... 调用您的可执行文件。查看start /? 的选项。
  • 或者您也可以在安装程序中插入一个小帮助工具,例如RunHiddenConsole.exeHideExec.exe,然后通过它调用您的可执行文件。

    1. 包括辅助工具

      [Files]
      Source: RunHiddenConsole.exe; DestDir: {tmp}; Flags: dontcopy
      
    2. 提取

      // extract unzip util from the compressed setup to temp folder and define a shortcut
      ExtractTemporaryFile('RunHiddenConsole.exe');
      hideConsole := ExpandConstant('{tmp}\RunHiddenConsole.exe');
      
    3. 添加包装函数 RunProcessHidden() 以使用 Command 参数调用工具

      // 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;
      

【讨论】:

  • 感谢您的回复。但我需要使用 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,ewWaitUntilTerminated, ResultCode);它工作正常。默默地调用 cmd 并安装设置。但在 RunProcess() 中,它不是静默执行,而是打开命令提示符。
  • /S 可能是 setup exe 的静音模式开关,结合 mit SW_HIDE。很高兴你解决了!
  • 如何在 RunProcess 方法中传递这些参数。由于静默安装的命令是:ntp-setup-win32.exe /USEFILE=C:\MeinBergNTP.ini
猜你喜欢
  • 1970-01-01
  • 2010-11-18
  • 1970-01-01
  • 1970-01-01
  • 2021-02-14
  • 2015-11-25
  • 2012-08-15
  • 2011-09-13
相关资源
最近更新 更多