Thread overview
How make Executable Dlang EXE ask for "Run as Administrator"?
Feb 01, 2020
Marcone
Feb 01, 2020
Ferhat Kurtulmuş
Feb 03, 2020
Marcone
Feb 03, 2020
Ferhat Kurtulmuş
Feb 07, 2020
Marcone
February 01, 2020
I created a program in Dlang and compiled to exe using dmd.
But my program need administrator privileges. How can I make executable dlang program ask for administrator privileges on start up program?
February 01, 2020
On Saturday, 1 February 2020 at 06:26:04 UTC, Marcone wrote:
> I created a program in Dlang and compiled to exe using dmd.
> But my program need administrator privileges. How can I make executable dlang program ask for administrator privileges on start up program?

Disclaimer: did not tried. You must somehow embed this manifest file into your exe using  some linker parameter. Or put this manifest next to your exe by naming it MyApplication.exe.manifest.

<?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="MyApplication"
     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="requireAdministrator"
          uiAccess="false"/>
        </requestedPrivileges>
       </security>
  </trustInfo>
</assembly>


February 03, 2020
On Saturday, 1 February 2020 at 08:14:19 UTC, Ferhat Kurtulmuş wrote:
> On Saturday, 1 February 2020 at 06:26:04 UTC, Marcone wrote:
>> [...]
>
> Disclaimer: did not tried. You must somehow embed this manifest file into your exe using  some linker parameter. Or put this manifest next to your exe by naming it MyApplication.exe.manifest.
>
> <?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="MyApplication"
>      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="requireAdministrator"
>           uiAccess="false"/>
>         </requestedPrivileges>
>        </security>
>   </trustInfo>
> </assembly>

Work very well when I put this manifest next to your exe by naming it MyApplication.exe.manifest. But how embed this manifest file into exe using linker parameter? Can you send me the exemple command?
February 03, 2020
On Monday, 3 February 2020 at 12:27:41 UTC, Marcone wrote:
> On Saturday, 1 February 2020 at 08:14:19 UTC, Ferhat Kurtulmuş wrote:
>> On Saturday, 1 February 2020 at 06:26:04 UTC, Marcone wrote:
>>> [...]
>>
>> Disclaimer: did not tried. You must somehow embed this manifest file into your exe using  some linker parameter. Or put this manifest next to your exe by naming it MyApplication.exe.manifest.
>>
>> <?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="MyApplication"
>>      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="requireAdministrator"
>>           uiAccess="false"/>
>>         </requestedPrivileges>
>>        </security>
>>   </trustInfo>
>> </assembly>
>
> Work very well when I put this manifest next to your exe by naming it MyApplication.exe.manifest. But how embed this manifest file into exe using linker parameter? Can you send me the exemple command?

A quick google search shows many ways:

1) https://stackoverflow.com/questions/44030618/embedding-manifest-to-exe-file/44031483
this one would have worked if we had a working GDC compiler on windows. Just skip to another option:

2) https://docs.microsoft.com/en-us/cpp/build/how-to-embed-a-manifest-inside-a-c-cpp-application?view=vs-2019

mt.exe -manifest MyApp.exe.manifest -outputresource:MyApp.exe;1

PS: mt.exe is available with my cmd because Windows Kits are installed on my Windows computer. I don't know how to have it working otherwise.

3) https://docs.microsoft.com/en-us/cpp/build/reference/manifest-create-side-by-side-assembly-manifest?view=vs-2019

This requires you to use visual studio. Maybe it can be achieved with VisualD, I don't know.
February 07, 2020
Solved adding this code in resource.rc, converted to resource.res and linked to .d source.

This code add the file "manifest.manifest" to resource.

1 24 "manifest.manifest"