2009-11-23 19 views
5

Vista &からWindows 7が出ました。.NETアプリケーションの一部がセキュリティ例外をスローし始めました。管理者として.NETアプリケーションを実行

いくつかのアプリケーション(ウィルス対策、コントロールパネル)に小さなシールドが付いていることに気付きました。これらのアプリケーションを実行すると、Windowsによって自動的に管理者権限が要求されます。

私は、管理者として実行するようにアプリケーションを設定できますが、それは十分ではありません。なぜなら、アプリケーションが特権なしで実行されると、ユーザーのマシンでクラッシュするからです。

Windowsに(プログラムで)通知する方法はありますか?管理者権限でアプリケーションを実行したいですか?

答えて

7

アプリケーションマニフェストで管理者権限を必要とするとしてマークする必要があります。プロセスを説明するHere's an article from MSDN Magazine

16

、アプリケーションマニフェストを作成しますrequireAdminstratorへのrequestedExecutionLevelを設定します。

例(あなたがアプリケーションマニフェストに追加する際VSによって生成された):

<?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 Manifest Options 
      If you want to change the Windows User Account Control level replace the 
      requestedExecutionLevel node with one of the following. 

     <requestedExecutionLevel level="asInvoker" uiAccess="false" /> 
     <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> 
     <requestedExecutionLevel level="highestAvailable" uiAccess="false" /> 

      If you want to utilize File and Registry Virtualization for backward 
      compatibility then delete the requestedExecutionLevel node. 
     --> 
     <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> 
     </requestedPrivileges> 
    </security> 
    </trustInfo> 
</asmv1:assembly> 

は、Visual Studioアプリケーションのプロジェクトにこれを追加した場合、それコンパイル時にアセンブリに埋め込まれます。

関連する問題