Tuesday, October 09, 2007

Installing with or without administrator privileges

To create the installer for Task Coach on Windows, I use the excellent Innosetup tool. I upgraded to the latest version of Innosetup a while ago but didn't notice immediately that the installer created by this new version of Innosetup required the user to have administrator privileges. Because Task Coach is aimed at ordinary users, that is not acceptable.

It took me some time to find out how to have the installer work for both users with and without administrator privileges. I'm recording the solution here so that other developers may benefit from it.

In the registry section of the Innosetup script I included two versions of the lines that associate the ".tsk" extension with Task Coach. The first four lines (*) are used if the user has administrator privileges (Check: IsAdminLoggedOn), but the last four lines are used if the user has no administrator rights (Check: not IsAdminLoggedOn).

(*) I had to split the lines to prevent them from being clipped. The line continuations are indented.


[Registry]
Root: HKCR; Subkey: ".tsk"; ValueType: string; ValueName: "";
ValueData: "TaskCoach"; Flags: uninsdeletevalue;
Check: IsAdminLoggedOn
Root: HKCR; Subkey: "TaskCoach"; ValueType: string; ValueName: "";
ValueData: "Task Coach File"; Flags: uninsdeletekey;
Check: IsAdminLoggedOn
Root: HKCR; Subkey: "TaskCoach\DefaultIcon"; ValueType: string;
ValueName: ""; ValueData: "{app}\TaskCoach.EXE,0";
Check: IsAdminLoggedOn
Root: HKCR; Subkey: "TaskCoach\shell\open\command";
ValueType: string; ValueName: "";
ValueData: """{app}\TaskCoach.EXE"" ""%%1""";
Check: IsAdminLoggedOn
Root: HKCU; Subkey: "Software\Classes\.tsk"; ValueType: string;
ValueName: ""; ValueData: "TaskCoachFile";
Flags: uninsdeletevalue; Check: not IsAdminLoggedOn
Root: HKCU; Subkey: "Software\Classes\TaskCoachFile";
ValueType: string; ValueName: ""; ValueData: "Task Coach File";
Flags: uninsdeletekey; Check: not IsAdminLoggedOn
Root: HKCU; Subkey: "Software\Classes\TaskCoachFile\DefaultIcon";
ValueType: string; ValueName: "";
ValueData: "{app}\TaskCoach.EXE,0"; Check: not IsAdminLoggedOn
Root: HKCU; Subkey: "Software\Classes\TaskCoachFile\shell\open\command";
ValueType: string; ValueName: "";
ValueData: """{app}\TaskCoach.EXE"" ""%%1""";
Check: not IsAdminLoggedOn