2

Inno Setup documentation says the following:

{group} The path to the Start Menu folder, as selected by the user on Setup's Select Start Menu Folder wizard page. This folder is created under the All Users profile unless the user installing the application does not have administrative privileges, in which case it is created in the user's profile.*

When I use PrivilegesRequired=admin (i.e. the default), Start menu items are created for all users in C:\ProgramData\Microsoft\Windows\Start Menu\Programs.

When I use PrivilegesRequired=lowest, but run setup with right-click run-as-administrator, Start menu items are created for just the admin user in C:\Users\admin-user\AppData\Roaming\Microsoft\Windows\Start Menu\Programs. This happens even if the current user is an admin.

How can I make start menu items be for all users when using right-click elevation? In this situation, Setup installs program files for all users in C:\Program Files\. So I would like start menu items also to be for all users.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
user3142056
  • 337
  • 2
  • 9

2 Answers2

2

Use a scripted constant to dynamically change Start menu root path, based on an elevation status of the installer.

You have to use WinAPI (e.g. SHGetFolderPath) to retrieve the path to common Start menu folder, as {commonprograms} actually return {userprograms}, if PrivilegesRequired=lowest, even when the installer is actually running elevated.

[Icons]
Name: "{code:GetMenuRootPath}\{groupname}\My Program"; Filename: "{app}\MyProg.exe"
[Code]

const
  CSIDL_COMMON_PROGRAMS = $0017;
  SHGFP_TYPE_CURRENT = 0;
  MAX_PATH = 260;
  S_OK = 0;

function SHGetFolderPath(
  hwnd: HWND; csidl: Integer; hToken: THandle; dwFlags: DWORD;
  pszPath: string): HResult;
  external 'SHGetFolderPathW@shell32.dll stdcall';

function GetMenuRootPath(Param: string): string;
var
  R, I: Integer;
begin
  if IsAdminLoggedOn then
  begin
    SetLength(Result, MAX_PATH);
    R := SHGetFolderPath(0, CSIDL_COMMON_PROGRAMS, 0, SHGFP_TYPE_CURRENT, Result); 
    if R <> S_OK then
    begin
      Log('Failed to resolve path to common Start menu folder');
    end
      else
    begin  
      SetLength(Result, Pos(#0, Result) - 1);

      Log(Format('Resolved path to common Start menu folder: %s', [Result]));
    end;
  end
    else
  begin
    Result := ExpandConstant('{userprograms}');
    Log(Format('Using user''s Start menu folder: %s', [Result]))
  end;
end;

The code is for Unicode version of Inno Setup (the only version as of Inno Setup 6).


Though note that using groups in Start menu is against Windows guidelines for Windows 8 and newer.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
1

You can use the (deprecated and now undocumented) value PrivilegesRequired=none to make Inno adapt to whether it is being run with or without admin privileges, including redirecting the Start Menu entries accordingly.

However the reason that this setting is deprecated is because the entire concept is a little silly. Most applications should be designed to require admin privileges to install (since typically people who are non-admins are not supposed to install software).

If you do end up with an application installed both as an admin and as a regular user then you will have cases where certain users will see two copies of the application installed and will not know which one to use. Furthermore the admin might upgrade the one they installed thinking that all users will see it, but meanwhile some users are still using the older version.

I strongly encourage you to abandon the idea of letting unprivileged users install your application and just stick with PrivilegesRequired=admin, or if you really want to allow that, then PrivilegesRequired=lowest.

If you do use PrivilegesRequired=lowest, then also use {userpf} in your DefaultDirName so that it doesn't install to Program Files if someone erroneously runs it as an admin.

Miral
  • 12,637
  • 4
  • 53
  • 93
  • When a computer is air-gapped (has no internet access), and the user has no Administrator access to the PC, it is vital for the unprivileged user to be able to upgrade the installed software. PrivilegesRequired=lowest fails in Inno v 6 when attempting to create the menu items as noted. Hopefully the {userpf} trickola will work for my use case. Thanks for the tip. – guitarpicva Apr 18 '20 at 16:21
  • The application actually does install with "lowest", it's only the Start Menu items that fail. – guitarpicva Apr 18 '20 at 16:27
  • For my use case stated above in these comments: Specifying "{userprograms}" and "{userdesktop}" in the [Icons] section works without any errors reported at install time. I use "lowest" as privileges required. – guitarpicva Apr 18 '20 at 16:47