- 追加された行はこの色です。
- 削除された行はこの色です。
[[Open棟梁>https://github.com/OpenTouryoProject]] wiki
-[[戻る>IdentityImpersonation]]
*目次 [#x05788f7]
#contents
*概要 [#s3e7414f]
区間偽装のサンプルです。
Open棟梁の[[IdentityImpersonation]].[[ImpersonateValidUser+UndoImpersonationメソッド>https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/C%23/Frameworks/Infrastructure/Public/Util/IdentityImpersonation.cs#L144]]を使用しています。
try
{
// コードの特定部分を実行するときのみ、任意のユーザを偽装する。
// 偽装して
ii = new IdentityImpersonation();
ret = ii.ImpersonateValidUser("x", "", "x");
// ファイルを開く
Console.WriteLine(
string.Format("ユーザ「{0}」を偽装):", WindowsIdentity.GetCurrent().Name)
+ ResourceLoader.LoadAsString(@"c:\test.txt", Encoding.GetEncoding(CustomEncode.UTF_8)));
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
finally
{
// 偽装解除
ret = ii.UndoImpersonation();
}