16

I've made a Visual Studio Setup Project with Visual Studio 2008 (SP1) for an Office 2007 AddIn. The setup only copies files to a per-user location (LocalAppData) and only writes registry settings to HKEY_CURRENT_USER, but when run under Windows 7, the MSI asks for admin credentials just before it begins copying files. The installer works perfectly running under a limited user account on Windows XP, but under Windows 7, admin privileges seem to be required.

I have not been able to find a way to remove the admin elevation requirement and I want to know how to do this or if it is not possible to do this with a Visual Studio Setup Project.

UPDATE 2010-11-03 (more details)

When I build the Visual Studio Setup Project, it creates a setup.exe and an MSI file. Visual Studio 2008 does not seem to give me adequate control over how the setup.exe is created or how the MSI file is created. The setup.exe file seems to be only for installing any prerequisites that my Office 2007 AddIn may need. It is the MSI file, which can be run independently, that installs the actual Office 2007 AddIn. I want to learn how to mark the MSI file such that it does not ask for admin privileges, because my MSI file only copies files to a per-user location and only writes registry settings to HKEY_CURRENT_USER.

Carlo Zanocco
  • 1,967
  • 4
  • 18
  • 31
Mike W
  • 301
  • 1
  • 2
  • 10

3 Answers3

14

I believe I have found the answer on this page:

Link


How do I build a Standard User package?

This takes a bit of work to make a package install only to the locations a Standard User has permission. Some of the requirements are

  1. Use a Type 51 Custom Action in the InstallUISequence to always unset the ALLUSERS (the per-user option)

  2. Files must be written only to folders that Standard User has access to. Assuming the ALLUSERS is always set to the per-user setting, you can use the redirectable folder properties but not ProgramFilesFolder as it does not redirect on per-user.

  3. Install app to a location under LocalAppDataFolder.

  4. All registry settings should be written to HKCU which is 1 in the Registry Table’s Root column.

  5. Flip bit 3 of the word count property in the summary information stream to signal no credential prompt is required.

  6. If you have a bootstrapper (typically named setup.exe), manifest the requestedExecutionLevel to run asInvoker.

  7. Pass ICE Validation as the ICEs have checks for incorrectly mixing per-user and per-machine state.

  8. Test both from a Standard User account and from an elevated command prompt to confirm behavior.

  9. Provide your users’ documentation of the user specific nature of the package as this is atypical in today’s application installs.


NOTE: Step 5 can be done using Orca, Microsoft's MSI editing tool. Open the MSI file in Orca, select View-->Summary Information... then check the "UAC Compliant" checkbox.

NOTE #2: Step 5 can be done using the WiSumInf.vbs sample script file included in the Microsoft SDK: C:\Program Files\Microsoft SDKs\Windows\v7.0\Samples\sysmgmt\msi\scripts\WiSumInf.vbs

NOTE #3: Step 1 seems to be taken care of in a Visual Studio Step Project by right-clicking on the setup project, choosing View-->User Interface, getting properties for the "Install/Start/Installation Folder" page and setting "InstallAllUsersVisible" to False.

NOTE #4: Yet another way to do Step 5, use the MsiInfo.exe tool included in the "Windows SDK Components for Windows Installer Developers" http://msdn.microsoft.com/en-us/library/aa370310(VS.85).aspx

Addition to the NOTE #4: Assuming that you are using long file names and compressed media (default behavior for an MSI) the PostBuildEvent command would be something like:

"C:\Program Files (x86)\Windows Kits\8.1\bin\x86\MsiInfo.exe" "$(BuiltOuputPath)" /w 10

Note that you will have to change the path to the MsiInfo to match the one that it has in your system.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Mike W
  • 301
  • 1
  • 2
  • 10
14

For Visual Studio v2017 with Visual Studio ​Installer Projects v0.9.1:
This solution requires a commandline tool that is installed as part of the Windows SDK

  1. In Visual Studio: select the Visual Studio Installer project in Solution Explorer.
    Press the F4 key to see the project properties
    Set InstallAllUsers to false

  2. Right click the project in Solution Explorer > View > File System
    Select Application Folder. (right click > Properties Window)
    Change [ProgramFilesFolder] to [LocalAppDataFolder]

  3. Build the MSI
    (Right click the project in Solution Explorer > Build)

  4. Open a command prompt or add a postbuild event to run the Windows SDK utility msiinfo.exe - example:
    "C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x86\MsiInfo.exe" "c:\yourprogram\installer.msi" -w 10

Notes: The msiinfo.exe -w 10 switch sets the MSI "Word Count Summary" property of the MSI file to "compressed - elevated privileges are not required to install this package". More info here

mpowrie
  • 603
  • 8
  • 14
  • 1
    simple. clean. efficient and effective.. worked flawlessly.. many thanks.. used the post build event. – Heriberto Lugo Jun 20 '19 at 19:27
  • 1
    One question regarding point 4.: How can I create a post-build-event for installer project. I cannot find the option in the properties of the project. @HeribertoLugo how did you do it? – Bernhard Zechmeister Aug 31 '20 at 12:27
  • I used a post build task if I remember correctly. Ms build task. There's an interface you implement, and override a method, specify what you want in there. You can also send it parameters during the publishing stage. – Heriberto Lugo Sep 06 '20 at 21:52
  • Other than that I don't remember anything else. This was over a year ago and I work at a different company. So I can't check to see what I did. Sorry. – Heriberto Lugo Sep 06 '20 at 21:54
  • https://learn.microsoft.com/en-us/visualstudio/msbuild/task-writing?view=vs-2019 – Heriberto Lugo Sep 06 '20 at 21:57
  • You can also specify post build things in the text box under properties, or in a special file in solution which i can't remember the name of now. – Heriberto Lugo Sep 06 '20 at 22:03
  • This was the file I couldn't remember. .Targets file .. https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-dot-targets-files?view=vs-2019 – Heriberto Lugo Jun 17 '21 at 02:19
  • I found the answer now how to create a post-build-event here: https://stackoverflow.com/q/12727631/2247674 Press F4 to display the Properties window Click on the name of your setup/deployment project in the Solution Explorer Click on the PostBuildEvent item in the Properties window to cause a button labeled "..." to appear Click on the "..." button to display the Post-build Event Command Line dialog Add a command line of your choice in the Post-build event command line text box Build your project in Visual Studio and verify that the post-build event is executed after the main MSI build – Bernhard Zechmeister Aug 27 '21 at 13:34
  • 1
    You can use `$(BuiltOuputPath)` in your post build event to apply it to the MSI dynamically. So on VS2022 the PostBuildEvent = `"C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x86\MsiInfo.exe" $(BuiltOuputPath) -w 10` – HackSlash Sep 06 '22 at 22:49
  • And you can use `%PROGRAMFILES(x86)%` environment variable then the PostBuildEvent = `"%PROGRAMFILES(x86)%\Windows Kits\10\bin\10.0.19041.0\x86\MsiInfo.exe" "$(BuiltOuputPath)" -w 10` (but still the Windows SDK version has to be adapted) – Bernhard Zechmeister Sep 13 '22 at 19:31
0

If your installer is named 'setup.exe' or 'install.exe', Win7 "knows" it's an installer and will run it in 'requires administrator' mode by default. You'll need to add a manifest your installer (internal or external) to tell it to run with lesser permissions.

A sample manifest from MSDN is shown below. Change the value 'IsUserAdmin' to your program name, then save it as 'executablename.exe.manifest' in the folder alongside the exe.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
  <assemblyIdentity version="1.0.0.0"
     processorArchitecture="X86"
     name="IsUserAdmin"
     type="win32"/> 
  <description>Description of your application</description> 
  <!-- Identify the application security requirements. -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="asInvoker"
          uiAccess="false"/>
        </requestedPrivileges>
       </security>
  </trustInfo>
</assembly>

See the article here for more information.

DaveE
  • 3,579
  • 28
  • 31
  • I'm not sure that I can apply that solution to my scenario. When I build my Visual Studio Setup Project, it creates a setup.exe and an MSI file. Also, Visual Studio 2008 does not seem to give me adequate control over how these files are created. The purpose of the setup.exe seems to be only to install any prerequisites that may need to be installed. But, it is the MSI file that does the actual installation of the files and registry keys for my AddIn. I need to figure out what to do to the MSI file to make this work. – Mike W Nov 03 '10 at 15:22