3

I tried the options listed in the other Questions, the registry settings and the 'change a bit' in the executable. But neither seems to work in the latest Windows 10 builds. The HKLM and HKLU have the same entries indicating the program is to 'run as administrator'. If I manually select 'Run as administrator' the program operates correctly. By correctly, I mean it reads its Registry keys correctly, otherwise it seems not to find the keys. I was not using the '~', so I added the '~' and it seems to have other problems reading it registry keys; "This key is already associated with an element of the collection."

The Properties of the file do not reflect the 'Run As Administrator' setting. That is the check-box is not selected even though the registry values are set. If I set the 'check-box' myself the program runs correctly. In the registry it shows '~ RUNASADMIN'.

Setting the registry seemed to work ok for Windows 10 from @2016.

In the Registry there is another group called 'Compatibility Assistant'-'Store'. In that folder there are other references to my program and then a block of some binary data. Looks to be 94hex bytes long.
Am I supposed to doing something with those as well?

I am using the following code:

Root: HKCU; Subkey: "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"; ValueType: multisz; \ 
ValueName: "{#InstallFolder}\myapp.exe"; ValueData: "RUNASADMIN"; \
            Flags: uninsdeletekeyifempty uninsdeletevalue; MinVersion: 0,6.2

I then write the same information to HKLM. (Which does not appear to be written at all.)

myapp.exe is a VB6 program from the early 2000's I do not think there's an app.manifest file.

The 'other questions': How to set 'Run as administrator' on a file using Inno Setup The second answer mentions running an Inno function after installing the item and it appears to me that that function is setting a byte in the file.

Stream.ReadBuffer(Buffer, 1);
    Buffer[1] := Chr(Ord(Buffer[1]) or $20);
    Stream.Seek(-1, soFromCurrent);
    Stream.WriteBuffer(Buffer, 1);

After some further testing this is what I have found. It looked like the manifest was working. (By working I mean reading and writing the HKLM-WOW6432Node keys the programs use to share some settings.) I renamed the manifest to prove it was doing something, and it appeared to be. I created an AppCompatFlag set to runasadmin, that appeared to work. I removed the key and it did not work; as expected, I put the key back and the manifest back but neither appear to work; the program is reading and writing to the Virtual Store keys and not the HKLM-WOW6432Nodes keys.

What it looks like is happening is the first time the program runs, there's no virtual store so it reads from the HKLM key, that makes the program look like it is working. But then when I change a setting it writes to the virtual store key and not the HKLM-WOW6432Node key. Then after that it always reads from the virtual store key and completely ignores the HKLM key. I have the manifest and the AppCompatFlags all set to 'runasadmin' and the icon has the UAC shield. If I delete the Virtual Store keys, the program reads from the HKLM-WOW6432Node keys, but the writes always go to the Virtual Store keys.

If I explicitly 'run as admin' from the 'right-click' menu then it reads from and writes to the HKLM-WOW6432Node keys as desired. So maybe it looked like it worked because all the program was redirected to the Virtual store keys. As soon as one program was 'run as admin' (from the right-click menu) that program would only read from the HKLM-WOW6432Node keys and that would then fail. What's also odd is that one program will read from the Virtual Store keys, but another program still reads from the HKLM-WOW6432Node keys. Both programs are signed... Maybe I've got too many things indicating 'run as administrator'. I also had WINXPSP3 mode selected, maybe that was causing the redirects.

Ryan Buton
  • 341
  • 3
  • 11
  • 1
    "change a bit" - what does that mean? Your myapp.exe should probably get an app.manifest file with `` – Thomas Weller Jul 11 '23 at 20:42
  • I've tested the code from the [other question](https://stackoverflow.com/q/16978917/850848). The `SetElevationBit` approach does not seem to work any more indeed. But the `AppCompatFlags` does work. Windows 10 22H2. – Martin Prikryl Jul 21 '23 at 16:05

1 Answers1

4

myapp.exe is a VB6 program from the early 2000's I do not think there's an app.manifest file.

Than simply create one. If it's in the same directory as myapp.exe and is named myapp.exe.manifest, Windows will use it.

You can even embedded it into myapp.exe, see below. Sample manifest file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
    Executable: myapp.exe
    Manifest:myapp.exe.manifest
    Sample application manifest file:
-->
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
  <assemblyIdentity version="1.0.0.0"
     processorArchitecture="X86"
     name="myapp"
     type="win32"/> 
  <description>Description of your application</description> 
   <dependency>
      <dependentAssembly>
         <assemblyIdentity 
                 type="win32" 
                 name="Microsoft.Windows.Common-Controls" 
                 version="6.0.0.0" 
                 processorArchitecture="X86" 
                 publicKeyToken="6595b64144ccf1df" 
                 language="*" />
           </dependentAssembly>
   </dependency>
  <!-- Identify the application security requirements. -->
  <!-- 
    level="asInvoker" oder "highestAvailable" oder "requireAdministrator"
    Quelle: http://msdn.microsoft.com/en-us/library/bb756929.aspx
  -->
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="requireAdministrator"
          uiAccess="false"/>
        </requestedPrivileges>
       </security>
  </trustInfo>
</assembly>

You can embed this manifest into the executable using MS' mt.exe.

The accepted answer shows the syntax on how to do so.

Hel O'Ween
  • 1,423
  • 9
  • 15
  • Wow, did not know this was possible. I will give it a try. Thanks – Ryan Buton Jul 12 '23 at 12:25
  • I added the manifest as indicated above. Now some of the programs no cannot be signed. ******** Signing E:\Signing\myapp.exe ******** Done Adding Additional Store SignTool Error: SignedCode::Sign returned error: 0x800700C1 Either the file being signed or one of the DLL specified by /j switch is not a valid Win32 application. SignTool Error: An error occurred while attempting to sign: E:\Signing\myapp.exe. The files could be signed before adding the manifest. – Ryan Buton Jul 12 '23 at 21:27
  • We didn't try it out with signing (VB6 executables), so I can't add anything to that. But the first way, simply putting the appropriately named manifest file in the same directory as the executable, should hopefully still do the trick. – Hel O'Ween Jul 13 '23 at 07:44
  • I am trying that now. I didn't quite understand the 'same directory' comment. I thought, at first, that meant for the mt.exe to work the files had to be in the same directory. Later I thought, maybe he means at run-time. I am trying that now. – Ryan Buton Jul 13 '23 at 13:58
  • I placed the manifest files in the same folder as the exe's. Now some of the buttons look different than before. Seemingly random buttons appear to be 'greyed' out. I renamed the manifest file and the buttons looked normal again. Could the button issue be caused by name="Microsoft.Windows.Common-Controls" ? I really do not know. No one else here does either. Ah it is buttons with text only and not an image that appear different than before. – Ryan Buton Jul 13 '23 at 17:48
  • Yes to both: the myapp.exe.manifest file needs to reside in the same directory as myapp.exe itself. And yes, that section is responsible for that. Just comment out or remove the whole `````` node to revert to "normal" behavior. This basically enables the XP themes/styles, which you could also do in code with [```InitCommonControls()```](https://www.vbforums.com/showthread.php?442650-RESOLVED-InitCommonControlsEx). You may have run across code samples of this before perhaps. And not all VB intrinsic controls play well with this, e.g. nested Frames are an issue I'm aware of. – Hel O'Ween Jul 14 '23 at 14:08