How to bake in Administrator request into compiled .exe

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Fabimawn
Prole
Posts: 23
Joined: Wed Jan 04, 2023 11:28 am
Location: Lua

How to bake in Administrator request into compiled .exe

Post by Fabimawn »

Hello everyone at Love2D!

Today I finished up creating a tool that I want to distribute to my companies customers so they can easilly update their embedded systems via serial (targetted at Windows 7 or higher). This works amazingly on multiple COM ports at the same time with different threads, however I also descided to include an auto driver installer into the application so users don't have to go to device manager, and install the .inf themselves and that's where I hit a wall.

The problem is that the Microsoft pnputil install command required admin privileges to actually install the driver which means when I found out I have to either run that command as admin, or the application. I went for the "run the whole app as admin" approach since I don't want a driver installer thread to ask for admin rights for every new driver since new ones might be required in the future since my new embedded board is getting micro controllers from different brands, which also need updating.

What I tried was after compiling the application into a convinient .exe to replace the default manifest with the one in the picture which I patched with Mt.exe. Now when running the app I need to grant admin rights which is great but a "No game" screen shows which I can't explain why. When patching the app with the default love2D manifest where you are not asked for admin rights it finds the applications Lua files perfectly.

The question is, is there a better way to bake in admin rights into the program, or is something wrong with the manifest?
When baking the new manifest with resource hacker it goes smoothly, but this doesn't seem to be automatable via a CLI.

Sorry for the long post...
Attachments
Knipsel.PNG
Knipsel.PNG (14.85 KiB) Viewed 648 times
User avatar
steVeRoll
Party member
Posts: 140
Joined: Sun Feb 14, 2016 1:13 pm

Re: How to bake in Administrator request into compiled .exe

Post by steVeRoll »

Haven't tried it myself, but there's rcedit which is a command line tool for editing an EXE's resources, so automating it may be more practical than with resource hacker.
RNavega
Party member
Posts: 385
Joined: Sun Aug 16, 2020 1:28 pm

Re: How to bake in Administrator request into compiled .exe

Post by RNavega »

When you create a shortcut to an executable on Windows, in the properties of that shortcut you can set it to always "Run As Administrator". This is a flag on the shortcut file (.LNK), not the executable, which stays the same.

So a suggestion is to test creating a .LNK file to your executable, with that flag set. It appears to be the "RunAsUser" data flag:
User avatar
Fabimawn
Prole
Posts: 23
Joined: Wed Jan 04, 2023 11:28 am
Location: Lua

Re: How to bake in Administrator request into compiled .exe

Post by Fabimawn »

Thanks a lot for all the answers! interesting tool rcedit, however I tested "$ rcedit "path-to-exe-or-dll" --set-requested-execution-level "requireAdministrator"", and what it seems to do is set an incorrect manifest for the application which creates a manifest mismatch. About the shortcut way, it seems it also requires some trickery. I don't really trust MS on this, they might change one CMD command in the following years and it's broken. What I've descided to do is create a batch file converted to .exe that always opens a file from a relative path which is already patched for admin use, since batch files aren't so picky about their manifest file it seems (I tested this). The batch file gets copyied from the source every time I compile.

For anybody with this same problem. Create a batch file that starts your compiled app, and make sure to always use relative paths! Then just search for a batch to exe converter (which might already have admin option baked in), if not you can always use resource hacker to change the manifest by hand to something like this:

Code: Select all

<?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="amd64"
    name="CompanyName.ProductName.YourApp"
    type="win32" />
  <description></description>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
        type="win32"
        name="Microsoft.Windows.Common-Controls"
        version="6.0.0.0"
        processorArchitecture="amd64"
        publicKeyToken="6595b64144ccf1df"
        language="*" />
    </dependentAssembly>
  </dependency>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>
User avatar
Fabimawn
Prole
Posts: 23
Joined: Wed Jan 04, 2023 11:28 am
Location: Lua

Re: How to bake in Administrator request into compiled .exe

Post by Fabimawn »

Well this was a waste of time... Windows won't allow you to drag and drop in my case update binaries onto the Love2D application since it's now elevated and explorer.exe isn't. This means I am forced to use admin request per driver.

Edit solved it in a different thread if anybody is also magigally having two of the same issues as me: viewtopic.php?p=261452#p261452
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests