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

时间:2015-10-16 11:47:35

标签: inno-setup ini pascalscript

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()方法进行静默安装。

1 个答案:

答案 0 :(得分:1)

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

您可以使用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()

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

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;
      
相关问题