如何在 inno 脚本中传递 ini 脚本和 exe 设置
How to pass a ini script and a exe setup in inno script
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 文件作为参数传递。首先,我提取设置和 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()
函数(默认情况下),除非您自己创建它。
您可以使用 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;
Thanks for the reply. But I need to use RunProcess() as all other iss files are using this method only. With exec() method its working fine though :).
你可以写一个包装函数。
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.exe
或 HideExec.exe
,然后通过它调用您的可执行文件。
包括辅助工具
[Files]
Source: RunHiddenConsole.exe; DestDir: {tmp}; Flags: dontcopy
提取
// extract unzip util from the compressed setup to temp folder and define a shortcut
ExtractTemporaryFile('RunHiddenConsole.exe');
hideConsole := ExpandConstant('{tmp}\RunHiddenConsole.exe');
添加包装函数 RunProcessHidden() 以使用命令参数调用工具
// 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;
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 文件作为参数传递。首先,我提取设置和 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()
函数(默认情况下),除非您自己创建它。
您可以使用 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;
Thanks for the reply. But I need to use RunProcess() as all other iss files are using this method only. With exec() method its working fine though :).
你可以写一个包装函数。
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.exe
或HideExec.exe
,然后通过它调用您的可执行文件。包括辅助工具
[Files] Source: RunHiddenConsole.exe; DestDir: {tmp}; Flags: dontcopy
提取
// extract unzip util from the compressed setup to temp folder and define a shortcut ExtractTemporaryFile('RunHiddenConsole.exe'); hideConsole := ExpandConstant('{tmp}\RunHiddenConsole.exe');
添加包装函数 RunProcessHidden() 以使用命令参数调用工具
// 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;