2021年12月18日 星期六

How to make a Delphi application run as an administrator? Delphi High DPI switch between own scaling and Windows scaling

 https://itqna.net/questions/5331/how-make-delphi-application-run-administrator

  

Tip: To learn more about custom Manifest file you can give   a look at this Embarcadero link : Customizing the Windows   Application Manifest   File

 

https://docwiki.embarcadero.com/RADStudio/Tokyo/en/Customizing_the_Windows_Application_Manifest_File

 Customizing the Windows Application Manifest File

 

YOU CAN USE THIS FILE HERE

If you prefer you can use this ready, just do the following:

Content of the manifest file

  • Create a text file and paste the content below
  • Save in the folder of your project with the name you prefer, as long as you have the .manifest extension, the most common is that the file is named Manifest.manifest
  •  

     

     

    https://en.wikipedia.org/wiki/Manifest_file

     Windows Application Manifest File       name="Microsoft.Windows.Common-Controls"

     

     

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
     <dependency>
       <dependentAssembly>
         <assemblyIdentity
           type="win32"
           name="Microsoft.Windows.Common-Controls"
           version="6.0.0.0"
           publicKeyToken="6595b64144ccf1df"
           language="*"
           processorArchitecture="*"/>
       </dependentAssembly>
     </dependency>
     <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
       <security>
         <requestedPrivileges>
           <requestedExecutionLevel
             level="asInvoker"
             uiAccess="false"/>
           </requestedPrivileges>
       </security>
     </trustInfo>
    </assembly>

     

    // Set DPI Awareness depending on a registry setting
    with TRegIniFile.create('SOFTWARE\' + SRegName) do
    begin
      setting := readInteger('SETTINGS', 'scale', 0);
      Free;
    end;
    handle := LoadLibrary('shcore.dll');
    if handle <> 0 then
    begin
      setProcessDPIAwareness := GetProcAddress(handle, 'SetProcessDpiAwareness');
      if Assigned(setProcessDPIAwareness) then
      begin
        if setting < 2 then
          // setting <2 means no scaling vs Windows
          setProcessDPIAwareness(0)
        else
          // setting 2: 120%, 3: 140% vs. Windows
          // The actual used scaling factor multiplies by windows DPI/96
          setProcessDPIAwareness(1);
      end;
      FreeLibrary(handle);
      // Get windows scaling as Screen.PixelsPerInch was read before swiching DPI awareness
      // Our scaling routines now work with WinDPI instead of Screen.PixelsPerInch
      WinDPI:= Screen.MonitorFromWindow(application.handle).PixelsPerInch;
    end;
     
     
    Mage.exe (Manifest Generation and Editing Tool) - Microsoft ...
    https://docs.microsoft.com › dotnet › tools
    The Manifest Generation and Editing Tool (Mage.exe) is a command-line tool that supports the creation and editing of application and deployment ...
     文件擴展名首頁 / 所有軟體 / Heaventools Software / Heaventools Application Manifest Wizard

    Heaventools Application Manifest Wizard
    開發者名稱: Heaventools Software
    最新版本: 1.99 R6
    軟體類別: 開發者工具
    軟體子類別: XML 工具
    操作系統: Windows

    軟體概述

    應用程序清單嚮導是一個工具,允許遺留應用程序從Windows XP或Vista的共同控制的華而不實的新面貌受益。這個工具允許除了插入需要管理員級別為它添加UAC清單。這使得提高管理員對Windows 7和Vista的應用程序運行。這使得應用程序的操作行為等同於Windows XP。 

    沒有留言: