Inno Setup - Finding out what install options were used for an application - from the application

1.2k views Asked by At

I have an Inno Setup installer for an app that offers the user a choice between "Install for all users" and "Install just for me". If it is installed for all users, the INI file is placed in commonappdata and the settings are shared (this is a customer requirement). If it is installed for the current user, it is placed in Local settings appdata.

Once the app has been installed, what's the cleanest way for the app to "know" at run-time what the installation option used was and thus where it should read and save the INI file from? Also, I want the 'default' folder (the one the user is placed in the first time they try to open a data file) to be MyDocs for the single user install, and SharedDocs for the all users install, and I'm assuming the solution will work for that also.

1

There are 1 answers

9
Sertac Akyuz On BEST ANSWER

Let setup write a registry value under HKCU if "install just for me" is chosen. Query the key at program startup and determine the default folder accordingly.

If you're using a task to let the user choose the installation type, you can use a registry entry like this:

[Registry]
Root: HKCU; SubKey: SOFTWARE\MyCompany\MyProg; ValueType: dword; ValueName: InstallUserOnly; ValueData: 1; Tasks: install_just_for_me; Flags: UninsDeleteValue; 

Then at application startup you can do something like:

function GetSpecialFolderPath(Folder: Integer; CanCreate: Boolean): string;
begin
  SetLength(Result, MAX_PATH + 1);
  SHGetSpecialFolderPath(0, PChar(Result), FOLDER, CanCreate);
  Result := PChar(Result);
end;

...
var
  Reg: TRegistry;
  DefFolder: string;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    if Reg.OpenKey('\SOFTWARE\MyCompany\MyProg', False) then begin
      if Reg.ValueExists('InstallUserOnly') then
        DefFolder := GetSpecialFolderPath(CSIDL_PERSONAL, True)
      else
        DefFolder := GetSpecialFolderPath(CSIDL_COMMON_DOCUMENTS, True);
    end;
  finally
    Reg.Free;
  end;

You can of course also read the registry value if you like.