installscript - 在 installshield/installscript 中执行命令行语句

标签 installscript installshield-2011

如何在安装过程中在 installscript 中执行以下命令?

netsh.exe advfirewall firewall show rule name="PowerSI (Release ASI 16.64)" || NETSH.EXE advfirewall firewall add rule name="PowerSI (Release ASI 16.64)" dir=in action=allow program="d:\Cadence\HIM_asi1664\ASI\Update4\SpeedXP\SpeedXP Suite x64\PowerSI.exe" enable=yes profile=any description="d:\Cadence\HIM_asi1664\ASI\Update4\SpeedXP\SpeedXP Suite x64\PowerSI.exe"

请注意,上面的命令包含可执行文件名称,即 netsh.exe 两次,这就是问题所在。我首先使用整个命令作为可执行文件的名称并传递一个空字符串作为参数来尝试 LaunchAppAndWait。接下来我尝试将第一个 netsh.exe 作为程序名传递,将剩余的文本作为参数传递。这两种方法都不起作用。

最佳答案

由于问题专门与 InstallScript 相关,因此这里有一个用于此目的的简单函数。

// prototype void CmdExecute( STRING );
//---------------------------------------------------------------------------                                                                        
//  Function: CmdExecute
//
//   Purpose: Asynchronusly execute a command line statement in the background
//
//---------------------------------------------------------------------------
function void CmdExecute( szCommand )
begin   
    LaunchApplication( "cmd.exe", "/C " + szCommand, "", 
                        SW_HIDE, 0, LAAW_OPTION_NOWAIT );
end;

在您的特定情况下,如果您需要执行一系列命令,或者遇到其他复杂情况,我建议改用批处理文件。如果需要,您可以即时编写一个(获得纯 installscript 解决方案而不向项目添加文件),通过 LaunchApplication(或它的变体)运行它,然后将其删除。

作为一个不错的小技巧,我喜欢让这样的批处理文件自行删除。如何?在它的最后,添加:
cmd.exe /C timeout 30 >nul & del "%0" /q

这将启动一个单独的进程,因此不再使用批处理文件。整整 30 秒的延迟并不是真正必要的,但过去已经证明对我来说总是有效的。如果你想让它快点完成,你可以调整那个时间。关键是要确保可以删除批处理,如果它正在使用中就不能删除。

关于installscript - 在 installshield/installscript 中执行命令行语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24177181/

相关文章:

.net - CustomAction <action_name> 在 installshield 中返回了实际错误代码 1603

windows-installer - Windows 10 未在 installshield 上检测到

c++ - 在 Installscript 自定义操作中使用 C++ DLL

installscript - % 运算符对 InstallScript 中的字符串有什么作用?

php - 在安装 PHP 时设置 MySQL 配置数据

windows-installer - Installshield包括卫星dll

visual-studio-2010 - InstallShield LE "Another version of this product is already registered"

windows - InstallShield 2011 在系统上下文中立即执行