<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Electron請(qǐng)求管理員權(quán)限

          共 12013字,需瀏覽 25分鐘

           ·

          2021-08-31 11:43

          1請(qǐng)求管理員權(quán)限

          1. 方案一

          通過更改 electron-builder 中的配置。

          可以通過配置requestedExecutionLevel達(dá)到請(qǐng)求管理員權(quán)限打開應(yīng)用。

          參數(shù)說明:

          1. asInvoker:默認(rèn)配置
          2. requireAdministrator:管理員權(quán)限
          3. highestAvailable:可用的最高權(quán)限

          如上述代碼在electron-builder中的win選項(xiàng)中配置了requestedExecutionLevel, 如:requestedExecutionLevel:requireAdministrator或requestedExecutionLevel:highestAvailable。重新打包安裝后,打開應(yīng)用,應(yīng)用會(huì)去請(qǐng)求管理員權(quán)限。

          修改后的應(yīng)用圖標(biāo)右下角多了個(gè)盾牌的標(biāo)志。

          2. 方案二

          這個(gè)方案需要借助第三方工具,所以比較繁瑣。

          通過mt.exe程序改造應(yīng)用。

          什么是mt.exe

          mt.exe是微軟官方出品的開發(fā)工具包中的一個(gè)軟件。

          該文件是一種生成簽名文件和目錄的工具。他要求清單中引用的文件與清單位于同一目錄中,使用安全散列算法sha-1的cryptoAPI實(shí)現(xiàn)生成散列。哈希作為十六進(jìn)制字符串插入到清單中的文件標(biāo)簽中。該工具目前僅生成sha-1哈希。

          利用mt.exe修改exe中manifest.xml文件來使應(yīng)用申請(qǐng)管理員權(quán)限。

          獲取mt.exe

          Mt.exe存在于Microsoft Windows Software Development Kit (SDK),可以通過安裝visualstudio獲得。飛鴻是通過安裝vs2017獲得這個(gè)sdk。在vs2017的可選功能里面,找到“通用windows開發(fā)工具”中的“windows 10 SDK”,安裝即可。

          配置環(huán)境變量

          為了在所有目錄下使用mt命令。

          下載完后,配置環(huán)境變量,就像配置jdk一樣。

          找到此電腦右鍵——高級(jí)系統(tǒng)設(shè)置——環(huán)境變量——系統(tǒng)變量新建——將mt.exe路徑存入。

          更改配置

          執(zhí)行mt命令在應(yīng)用中導(dǎo)出現(xiàn)有manifest.xml文件

          mt -inputresource:<your_exe_name>.exe;#1 -out:manifest.xml

          在manifest.xml中找到requestedExecutionLevel節(jié)點(diǎn),修改asInvoker為requireAdministrator或highestAvailable。

          最后執(zhí)行mt命令導(dǎo)入修改后的xml文件。

          mt -manifest manifest.xml -outputresource:<your_exe_name>.exe;1

          最后的最后,重新打包安裝后,打開應(yīng)用,應(yīng)用會(huì)去請(qǐng)求管理員權(quán)限。

          修改后的應(yīng)用圖標(biāo)右下角多了個(gè)盾牌的標(biāo)志。

          3. 源碼分析

          追究根源是每一個(gè)熱愛代碼的程序員最愛的事情。

          requestedExecutionLevel屬性存在于winOptions文件中。

          打包后在electron-builder/packages/app-builder-lib/src/options/winOptions.ts中。

          import {
              PlatformSpecificBuildOptions,
              TargetConfigType
          from "../index"
          import {
              CustomWindowsSign
          from "../codeSign/windowsCodeSign"

          export interface WindowsConfiguration extends PlatformSpecificBuildOptions {
              
              /**
             * 標(biāo)識(shí)要執(zhí)行應(yīng)用程序請(qǐng)求的安全級(jí)別
             * 此元素沒有子元素但具有以下屬性。
               標(biāo)識(shí)應(yīng)用程序正在請(qǐng)求的安全級(jí)別。 可能的值包括:

                  asInvoker,不請(qǐng)求其他權(quán)限。 此級(jí)別不需要其他信任提示。

                  highestAvailable,請(qǐng)求可用于父進(jìn)程的最高權(quán)限。

                  requireAdministrator,請(qǐng)求完全管理員權(quán)限。
             */

              /**
               * The [security level](https://msdn.microsoft.com/en-us/library/6ad1fshk.aspx#Anchor_9) at which the application requests to be executed.
               * Cannot be specified per target, allowed only in the `win`.
               * @default asInvoker
               */

              readonly requestedExecutionLevel ? : RequestedExecutionLevel | null
          }

          export type RequestedExecutionLevel = "asInvoker" | "highestAvailable" | "requireAdministrator"

          如果需要配置window中參數(shù)達(dá)到某種功能,我們可以仔細(xì)查看其中的配置項(xiàng)。

          export interface WindowsConfiguration extends PlatformSpecificBuildOptions {
              /**
               * 指定包的類型
               */

              /**
               * The target package type: list of `nsis`, `nsis-web` (Web installer), `portable` ([portable](/configuration/nsis#portable) app without installation), `appx`, `msi`, `squirrel`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir`.
               * AppX package can be built only on Windows 10.
               *
               * To use Squirrel.Windows please install `electron-builder-squirrel-windows` dependency.
               *
               * @default nsis
               */

              readonly target ? : TargetConfigType

              /**
               * 指定應(yīng)用圖標(biāo)地址
               * @default build/icon.ico
               */

              readonly icon ? : string | null

              /**
               * 商標(biāo)及注冊(cè)商標(biāo)。
               */

              readonly legalTrademarks ? : string | null
              /**
               * 使用簽名算法
               */

              /**
               * Array of signing algorithms used. For AppX `sha256` is always used.
               * @default ['sha1', 'sha256']
               */

              readonly signingHashAlgorithms ? : Array < "sha1" | "sha256" > | null
              /**
               * 用于簽名Windows可執(zhí)行文件的自定義函數(shù)(或文件或模塊id的路徑)。
               */

              /**
               * The custom function (or path to file or module id) to sign Windows executable.
               */

              readonly sign ? : CustomWindowsSign | string | null
              /**
               * 簽名的證書
               */

              /**
               * The path to the *.pfx certificate you want to sign with. Please use it only if you cannot use env variable `CSC_LINK` (`WIN_CSC_LINK`) for some reason.
               * Please see [Code Signing](/code-signing).
               */

              readonly certificateFile ? : string | null
              /**
               * 證書密碼
               */

              /**
               * The password to the certificate provided in `certificateFile`. Please use it only if you cannot use env variable `CSC_KEY_PASSWORD` (`WIN_CSC_KEY_PASSWORD`) for some reason.
               * Please see [Code Signing](/code-signing).
               */

              readonly certificatePassword ? : string | null
              /**
               * 簽名證書主題的名稱。
               */

              /**
               * The name of the subject of the signing certificate. Required only for EV Code Signing and works only on Windows (or on macOS if [Parallels Desktop](https://www.parallels.com/products/desktop/) Windows 10 virtual machines exits).
               */

              readonly certificateSubjectName ? : string | null
              /**
               * 簽名證書的SHA1哈希值。
               */

              /**
               * The SHA1 hash of the signing certificate. The SHA1 hash is commonly specified when multiple certificates satisfy the criteria specified by the remaining switches. Works only on Windows (or on macOS if [Parallels Desktop](https://www.parallels.com/products/desktop/) Windows 10 virtual machines exits).
               */

              readonly certificateSha1 ? : string | null
              /**
               * 要添加到簽名塊的附加證書文件的路徑。
               */

              readonly additionalCertificateFile ? : string | null
              /**
               * The URL of the RFC 3161 time stamp server.
               * @default http://timestamp.comodoca.com/rfc3161
               */

              readonly rfc3161TimeStampServer ? : string | null
              /**
               * The URL of the time stamp server.
               * @default http://timestamp.digicert.com
               */

              readonly timeStampServer ? : string | null

              /**
               * [The publisher name](https://github.com/electron-userland/electron-builder/issues/1187#issuecomment-278972073), exactly as in your code signed certificate. Several names can be provided.
               * 默認(rèn)為代碼簽名證書中的通用名稱。
               */

              readonly publisherName ? : string | Array < string > | null

              /**
               * 安裝前是否驗(yàn)證可用更新的簽名。
               * The [publisher name](#publisherName) 將用于簽名驗(yàn)證。
               *
               * @default true
               */

              readonly verifyUpdateCodeSignature ? : boolean

              /**
             * 標(biāo)識(shí)要執(zhí)行應(yīng)用程序請(qǐng)求的安全級(jí)別
             * 此元素沒有子元素但具有以下屬性。
               標(biāo)識(shí)應(yīng)用程序正在請(qǐng)求的安全級(jí)別。 可能的值包括:

                  asInvoker,不請(qǐng)求其他權(quán)限。 此級(jí)別不需要其他信任提示。

                  highestAvailable,請(qǐng)求可用于父進(jìn)程的最高權(quán)限。

                  requireAdministrator,請(qǐng)求完全管理員權(quán)限。
             */

              /**
               * The [security level](https://msdn.microsoft.com/en-us/library/6ad1fshk.aspx#Anchor_9) at which the application requests to be executed.
               * Cannot be specified per target, allowed only in the `win`.
               * @default asInvoker
               */

              readonly requestedExecutionLevel ? : RequestedExecutionLevel | null

              /**
               * 是否將元數(shù)據(jù)簽名并添加到可執(zhí)行文件中。高級(jí)選項(xiàng)。
               * @default true
               */

              readonly signAndEditExecutable ? : boolean

              /**
               * 是否簽名DLL文件。高級(jí)選項(xiàng)。
               * @see https://github.com/electron-userland/electron-builder/issues/3101#issuecomment-404212384
               * @default false
               */

              readonly signDlls ? : boolean
          }




          最后,希望大家一定要點(diǎn)贊三連。

          一個(gè)學(xué)習(xí)編程技術(shù)的公眾號(hào)。每周推送高質(zhì)量的優(yōu)秀博文、開源項(xiàng)目、實(shí)用工具、面試技巧、編程學(xué)習(xí)資源等等。目標(biāo)是做到個(gè)人技術(shù)與公眾號(hào)一起成長(zhǎng)。歡迎大家關(guān)注,一起進(jìn)步,走向全棧大佬的修煉之路


          瀏覽 483
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  亚洲欧美在线视频 | aaa三级黄片 | 日韩成人精品 | 99热手机在线精品 | 四虎影成人精品A片 |