Winform 擷取Win7 UAC 管理員權限

來源:互聯網
上載者:User

1.建立app.manifest 寫入配置內容  

<?xml version="1.0" encoding="utf-8"?><asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  <assemblyIdentity version="1.0.0.0" name="MyApplication.app" />  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">    <security>      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">        <!-- UAC 清單選項            如果要更改 Windows 使用者帳戶控制層級,請用以下節點之一替換             requestedExecutionLevel 節點。        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />            指定 requestedExecutionLevel 節點將會禁用檔案及登錄模擬。            如果要利用檔案及登錄模擬實現向後             相容性,則刪除 requestedExecutionLevel 節點。        -->        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />      </requestedPrivileges>    </security>  </trustInfo>  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">    <application>      <!-- 此應用程式設計使用的所有 Windows 版本的列表。Windows 將會自動選擇最相容的環境。-->      <!-- 如果應用程式設計使用 Windows 7,請取消注釋以下 supportedOS 節點-->      <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->    </application>  </compatibility>  <!-- 啟用 Windows 公用控制項和對話方塊的主題(Windows XP 和更高版本) -->  <!-- <dependency>    <dependentAssembly>      <assemblyIdentity          type="win32"          name="Microsoft.Windows.Common-Controls"          version="6.0.0.0"          processorArchitecture="*"          publicKeyToken="6595b64144ccf1df"          language="*"        />    </dependentAssembly>  </dependency>--></asmv1:assembly>

2.修改requestedExecutionLevel 中的level

3.在項目屬性中選擇應用程式項,然後在清單中選擇剛才加入的檔案app.manifest。

4.重新編譯器

5.在bin下運行程式可以看到表徵圖下已經出現標識

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.