Tuesday, June 4, 2013

Inno setup tips & tricks #1


Add application to windows firewall exceptions

Add the following code to [run] section:

[Run]
; Add firewall exception if needed
; Windows XP/2k3 version
Filename: {sys}\netsh.exe; Parameters: "firewall add allowedprogram program=""{app}\<application_name.exe>"" name=""ApexSQL <application>"" mode=ENABLE scope=ALL profile=ALL"; Flags: shellexec runhidden; MinVersion: 4,4; OnlyBelowVersion: 6.01,6.01; Check: IsFirewallExceptionSelected
; Windows Vista+ version
Filename: {sys}\netsh.exe; Parameters: "advfirewall firewall add rule name=""ApexSQL <application>"" dir=in action=allow program=""{app}\<application_name.exe>"" enable=yes profile=any"; Flags: shellexec runhidden; MinVersion: 6.01,6.01; Check: IsFirewallExceptionSelected

Notice that there are two versions - one for Windows XP/2k3 and other for Vista+. Windows Vista introduced updates to firewall and new mechanism of control. You can still use first line for all windows version, but it is deprecated and may not work on next windows version.
Flag Check: IsFirewallExceptionSelected determines return value from the custom page that controls weather this option is selected.
Additional notes:
MinVersion: 4,4 and OnlyBelowVersion: 6.01,6.01 are used to detect minimal and maximal windows version on which this task will be executed. It is important here to note that it requires two versions: old windows ver (dos based), windows NT ver.

Add program icon to quick-launch, but make it available only on windows xp
(and lower) where quick launch is supported

We use the trick with MinVersion and OnlyBelowVersion, but we need to add it to both [Tasks] and [Icons] sections:

[Tasks]
Name: quicklaunchicon; Description: Create a &Quick Launch icon; GroupDescription: Additional icons:; MinVersion: 4,4; OnlyBelowVersion: 6.01,6.01; Flags: unchecked
[Icons]
Name: {userappdata}\Microsoft\Internet Explorer\Quick Launch\<application>; Filename: {app}\<application_name.exe>; WorkingDir: {app}; MinVersion: 4,4; OnlyBelowVersion: 6.01,6.01; Tasks: quicklaunchicon; IconFilename: {app}\<application_name.exe>; IconIndex: 0

Disable useless setup pages
Lately we've been discussing application setup experience and have come to the conclusion that there are to many clicks and useless pages.

So here is the way to disable them:

Disable "ready" page shown just before installation starts. Just add the following directive to setup section:

[Setup]
DisableReadyPage=yes

To disable "select program group" page (start menu folder selection), we must use code section as we haven't yet updated to latest version of inno setup:

Add the following to code section:
[Code]
function ShouldSkipPage(PageID: Integer): Boolean;
begin
  { Skip start menu folder selection }
  Result := PageID = wpSelectProgramGroup;
end;

No comments:

Post a Comment