1

System32 でいくつかのファイルを削除する必要がある C# アプリケーションを開発しており、次のことを行っています。

File.Delete(@"c:\windows\system32\<file>");

これは機能していません。例外はスローされませんが、ファイルも削除されません。権限に関係していると思いますが、修正方法がわかりません。手伝ってくれますか?

4

3 に答える 3

2

まあ、あなたが悪意のあることをしていないと仮定しましょう ;) とにかく、試したことはありませんが、なりすましが役に立ちます。

Google 偽装 c# を使用すると、多くの例が表示されます。メールのアイデアは単純です。通常、コードはユーザーの特権で実行されます。偽装により、別のユーザーの特権でコードを実行できます (プログラム的に、ユーザーは何もする必要はありません)。したがって、ユーザーが UAC の制限なしでそのフォルダーに直接アクセスできる場合、理論的には、その時点で実行する必要があります。しかし、繰り返しますが、私はそれを試していないので、うまくいかなくても怒らないでください. ただのアイデア。

于 2011-07-06T20:53:37.577 に答える
1

Vistaまたは7(またはServer 2008+)でこれを行っている場合、UACも削除の邪魔になります。その場合、アプリケーションのマニフェストを変更して、アプリケーションの起動時にアクセス許可を昇格させる(または昇格したサブアプリまたはプロセスを起動する)ようにする必要があります。

http://victorhurdugaci.com/using-uac-with-c-part-1/

また、取得した例外を投稿すると、アクセス許可関連、x64関連、またはUACのいずれであるかが示唆されるため便利です。

于 2011-07-06T20:31:49.537 に答える
0

そのフォルダー内のファイルを変更するには、管理者アクセスが必要です。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="YourApplication.app" />
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
      <applicationRequestMinimum>
        <defaultAssemblyRequest permissionSetReference="Custom" />
        <PermissionSet ID="Custom" SameSite="site" Unrestricted="true" />
      </applicationRequestMinimum>
    </security>
  </trustInfo>
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!-- A list of all Windows versions that this application is designed to work with. Windows will automatically select the most compatible environment.-->
      <!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
      <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
    </application>
  </compatibility>
  <!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
  <!-- <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          processorArchitecture="*"
          publicKeyToken="789cf14ab782c1eb"
          language="*"
        />
    </dependentAssembly>
  </dependency>-->
</asmv1:assembly>
于 2011-07-06T21:08:31.497 に答える