1

I am trying to use a component condition for an admin manual pdf. If the installer is in the administrators group I want the admin manual to be installed. Here's how I'm setting this up but it's not being installed even if installer is an administrator. What am I missing?

Requirement:

InstallScope="perUser" />

<Condition>Privileged</Condition>

Find below:

 <Component Id="cmp_ManualForAdmins.pdf" Guid="4C28B047-74D2-4642-A180-0039B4C2C5BC">
    <File Id="fil_ManualForAdmins.pdf" Name="ManualForAdmins.pdf" Source="$(var.WindowsFormsApp1_TargetDir)ManualForAdmins.pdf">
      <Shortcut Id="startMenuAdminManual" Directory="ProgramMenuSubFolder" Name="AdminManual"></Shortcut>
    </File>
    <Condition>Privileged</Condition>
  </Component>
Rod
  • 14,529
  • 31
  • 118
  • 230

2 Answers2

0

I just spent an hour investigating this and there really aren't any good answers. Because the MSI is invoked from a standard user process and doesn't require elevation, MSI never knows the user can elevate so the Privileged property isn't set.

I figured a custom action might help to work around this but searching up C# Detect Admin revealed various classes and API calls that all had the same behavior.

If I install a protoype MSI from an elevated command prompt the condition evaluates to true and the 'admin.txt' file is installed. From a non elevated it is not installed.

So what would I do? One of two things:

1) Make a second Docs MSI that is a permachine install that requires elevation

or

2) Build and deploy a docs.exe which is manifested to require admin. If the program successfully elevates then have it extract the PDF from an embedded resource to the temp directory and do a ShellExecute to launch the default PDF viewer with that file.

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100
  • I guess some call can determine a users group membership - even for AD? Have a look at my alternative solution - does it make sense to you? I guess it depends how much you have to "hide" the admin.pdf from regular users (who can do administative installation if they know how to do so). – Stein Åsmul Mar 27 '20 at 15:01
  • Actually Admin Installs demonstrate that his desire to 'hide' the PDF can be easily thwarted. That and ORCA edits to the MSI. – Christopher Painter Mar 27 '20 at 15:11
  • Yes, found [IsUserAnAdmin function](https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-isuseranadmin), but can't test right now. Will do when I get back. Wonder if this is affected by elevation / UAC and stuff. – Stein Åsmul Mar 27 '20 at 15:21
  • This would all work just fine if he was doing a per-machine install. I'll add this to my list of reasons I don't do per-user installs. – Christopher Painter Mar 27 '20 at 16:13
0

Administrative Installation: Admins typically perform an administrative installation (file extraction) of a setup - at least if they work in big companies that do application packaging. Hence I tend to try to make files like that easily visible on the extracted source media - instead of installing them during normal installation (or both or either, doesn't matter which).

Sample administrative installation (glorified file extraction):

msiexec /a Test.msi TARGETDIR=D:\ExtractedFiles\

More about Administrative Installations.

Admin.pdf: Here is a quick hack that I haven't tested extensively. The admin.pdf will show up during file extraction and not during installation:

<..>

<Feature Id="MainApplication" Title="MainApplication" Level="1">
  <Feature Id="SomeFiles" Title="SomeFiles" Level="1" />

  <!-- Remove "Display" attibute to show Admin feature in normal setup GUI -->
  <Feature Id="Admin" Title="Admin" Level="1001" Display="hidden" />

</Feature>

<Directory Id="TARGETDIR" Name="SourceDir">

  <Component Id="AdminManual" Feature="Admin" Guid="{00000000-0000-0000-0000-0000DBFB0000}">
    <File Source="D:\Admin.pdf"  />
  </Component>

<..>

Running administrative installation will extract the admin.pdf to the top level extraction directory:

msiexec /a Test.msi TARGETDIR=D:\ExtractedFiles\

The Admin feature is hidden from the normal installation GUI. Change the attribute "Display" to change this. Just remove it for example - for testing purposes.

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164