premake / premake/premake-core

[VS] Add UAC configuration

Open
#2,132 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C
Stars
3.6k
Forks
654
Avg merge
1d 1h
Merged PRs (30d)
13

Description

What problem will this solve?

In Windows, you can set the required privilege level for an application by including an Application Manifest.

The field requestedExecutionLevel under trustInfo controls this, and has three levels: asInvoker, highestAvailable, requireAdministrator.

At its' simplest, such a manifest file can look like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>

Currently there is no option to set this with premake.

You can include a manifest simply by adding it to the files option, as such:

files { "myapp.exe.manifest" }

And it gets correctly added as Additional Manifest Files entry:

👍
image

The problem however is, that it's added as additional manifest, while the actual configuration property in the .vcxproj file isn't set accordingly.

👎
image

Besides the confusion, the real problem is that the build will fail:

1>manifest authoring error c1010001: Values of attribute "level" not equal in different manifest snippets.
1>LINK : fatal error LNK1327: failure during running mt.exe

This is because how manifests work in modern VS, which is that the additional manifests will be merged with whatever options you have set in the configuration, unlike earlier when manifests weren't controlled by configuration options and were embedded directly as raw resources instead. So now VS will have the requestedExecutionLevel field set twice, as both asInvoker and requireAdministrator and gets angry 😠

What might be a solution?

Add configuration options uacexecutionlevel and uacuiaccess for premake and the corresponding configuration properties in the .vcxproj file under <Project> → <ItemDefinitionGroup> → <Link>

<Project ...>
  <ItemDefinitionGroup ...>
    <Link>
      <UACExecutionLevel>AsInvoker</UACExecutionLevel>
      <UACUIAccess>false</UACUIAccess>
    </Link>
  </ItemDefinitionGroup>
</Project>

UACExecutionLevel = AsInvoker (default) / HighestAvailable / RequireAdministrator
UACUIAccess = false (default) / true

What other alternatives have you already considered?

I have seen other projects add /MANIFESTUAC to linkoptions as a workaround, as any command line options take precedence over whatever is configured in the project. This will make the project build, however it overrides the configuration property which will still show the wrong value (and makes changing it have no effect).

linkoptions { "/MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\"" }

The correct workaround to this is to use a call array override in premake like this.

if _ACTION and _ACTION >= "vs2010" then
  require "vstudio"
  premake.override(premake.vstudio.vc2010.elements, "link", function(base, prj)
    local calls = base(prj)
    table.insert(calls, function() premake.vstudio.vc2010.element("UACExecutionLevel", nil, "RequireAdministrator") end)
    return calls
  end)
end

This however isn't very user-friendly nor super obvious especially if you are not familiar with Lua. ( If you are not, go learn it now, lua is amazing 😄 )

So I think the best option is to add this as a proper feature so no workarounds are needed.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the premake.vstudio.vc2010.elements link entry point mentioned in the issue and inspect how existing configuration options become Link properties in generated .vcxproj files. The work is done when uacexecutionlevel and uacuiaccess produce the corresponding UACExecutionLevel and UACUIAccess properties without conflicting with an added manifest.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
build-system, devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.