How do I execute the following command in installscript during installation?
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"
Note that the above command contains the executable name i.e. netsh.exe
twice and this is where the problem is. I tried LaunchAppAndWait
first by using the whole command as the name of executable and passing an empty string as argument. Next I tried was passing the first netsh.exe as program name and the remaining text as argument. Both the approaches did not work.
Since the question is regarding InstallScript specifically, here's a simple function for this purpose.
// 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;
In your specific case, if you need to execute a series of commands, or if you run into other complications, I suggest using a batch file instead. If need be, you can write one on the fly (to have a pure installscript solution without adding files to the project), run it via LaunchApplication (or the variations of that) and then delete it afterwards.
As a nice little trick, I like to make such a batch file delete itself. How? At the end of it, add this:
cmd.exe /C timeout 30 >nul & del "%0" /q
This starts a separate process, so the batch file in no longer in use. The full 30 second delay isn't really necessary, but has proven to always work for me in the past. You can adjust that time, if you want it to hurry up and finish. The point is to make sure the batch can be deleted, which it can't be if it's in use.