Would some of the script look something like this?
rem //-------------------------------------------------------------------------
rem // Revert system settings as required by payload.
rem //-------------------------------------------------------------------------
ELETE_FIREWALL_RULES
rem //-------------------------------------------------------------------------
rem // UPnP IL.
rem //-------------------------------------------------------------------------
if %SERVICE_MANAGE_UPNP_FIREWALL_RULES% == NO goto SERVICE_DELETE_UPNP_FIREWALL_RULES_SKIP
rem //-------------------------------------------------------------------------
rem // Check if rule #1 exist.
rem //-------------------------------------------------------------------------
set COMMAND=%WINDIR%\System32\netsh.exe advfirewall firewall show rule name=!SERVICE_FIREWALL_UPNP_RULE_1_NAME!
set /A COMMANDS_COUNT=COMMANDS_COUNT+1
echo COMMAND[%COMMANDS_COUNT%][%DATE% - %TIME%]=[%COMMAND%] >> "%INSTALLER_LOG_FILE_NAME%" 2>&1
if %DEBUG% == YES echo COMMAND[%COMMANDS_COUNT%]=[%COMMAND%]
if %EXECUTE% == YES (
%COMMAND% >> "%INSTALLER_LOG_FILE_NAME%" 2>&1
)
if %ERRORLEVEL% == 0 (