Search code examples
inno-setupusergroupsprivilege

Creating shortcut in user Start menu from elevated Inno Setup installer


During its lifetime, MyApp creates extra shortcuts to Userappdata,

MyAppGroupName\MyAppShortcut#2
MyAppGroupName\MyAppShortcut#3
...

yet as Inno Setup requires elevation because of registry Association edits the original {Group} item is inserted in a different (commonstartmenu) directory:

MyAppGroupName\MyAppShortcutAtInstallation

Very happy with the {Group} flavour in the install so

DisableProgramGroupPage=yes

is not an option at this stage. Else creating paths in Dirs like

{Userappdata}\MyAppGroupName

doesn't appear to function in the current script:

        ...
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes
ChangesAssociations = yes


[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1

[Files]
; (Note: Scroll to the right to see the full lines!)
Source: "Test.exe"; DestDir: "{app}"; Flags: ignoreversion

[Icons]
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"

[Registry]
Root: HKCU; Subkey: "Software\Auth/MyApp"; Flags: uninsdeletekey
Root: HKCU; Subkey: "Software\Auth\MyApp"; ValueType: string; ValueName: "Name"; ValueData: "{app}";

;Association
Root: HKCR; Subkey: ".XXX";ValueData: "{#MyAppName}";Flags: uninsdeletevalue; ValueType: string; ValueName: ""
Root: HKCR; Subkey: "{#MyAppName}";ValueData: "Program {#MyAppName}";   Flags: uninsdeletekey; ValueType: string; ValueName: ""
Root: HKCR; Subkey: "{#MyAppName}\DefaultIcon";ValueData: "{app}\{#MyAppExeName},0";ValueType: string; ValueName: ""
Root: HKCR; Subkey: "{#MyAppName}\shell\open\command";ValueData: """{app}\{#MyAppExeName}"" ""%1""";ValueType: string;ValueName: ""


[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: en;  MessagesFile: "compiler:Default.isl"
Name: deu; MessagesFile: "compiler:Languages\German.isl"
Name: es;  MessagesFile: "compiler:Languages\Spanish.isl"

[Dirs]
Name: "{userstartmenu}\{userstartmenu}\{#MyAppName}"

[UninstallDelete]
Type: files; Name: "{#MyAppName}.chw"

Is there any known method of pointing {Group} to {Userappdata} in an elevated scenario? Or any other helpers e.g. here?


Solution

  • If I understand your question correctly you are looking for a combination of {userprograms} and {groupname}:

    [Icons]
    Name: "{userprograms}\{groupname}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
    

    Though note that:

    • Your approach is flawed in general. An installer should not both require elevation and modify environment of a specific user. The elevation can change user context (e.g. if Administrator account is distinct to the regular user account). So you do not know, if the "user" is the right user.
    • Using groups in Start menu is against Windows guidelines for Windows 8 and newer.