public void IdentityImpersonationScopeTest_Error() { using (IdentityImpersonationScope scope = new IdentityImpersonationScope("test", "test")) { WindowsIdentity identity = WindowsIdentity.GetCurrent(false); Assert.IsTrue(identity.Name.EndsWith("test")); File.WriteAllText(@"C:\Windows\System32\drivers\etc\test.txt", "嘿嘿哈嘿", Encoding.Default); } }
public void IdentityImpersonationScopeTest_Success() { using (IdentityImpersonationScope scope = new IdentityImpersonationScope("test", "test")) { WindowsIdentity identity = WindowsIdentity.GetCurrent(false); Assert.IsTrue(identity.Name.EndsWith("test")); File.ReadAllText(@"C:\Windows\System32\drivers\etc\hosts", Encoding.Default); } }