次のように WindowsIdentity Impersonation を使用すると:
WindowsIdentity newId = null;
WindowsImpersonationContext impersonatedUser = null;
Console.WriteLine("Name of the identity BEFORE impersonation: "
+ WindowsIdentity.GetCurrent().Name + ".");
newId = new WindowsIdentity(_impersonationToken);
impersonatedUser = newId.Impersonate();
Console.WriteLine("Name of the identity AFTER impersonation: "
+ WindowsIdentity.GetCurrent().Name + ".");
(私のコンピューターから winCE マシンにファイルをコピーするために使用されています。)
Name Before と Name After は同じものを返し続けます。なりすましの後に @ newId トークンを見ると、なりすましに使用するものと同じではありません。私がなりすましているトークンは、私がログインしているユーザーとは絶対に同じではありません。
私のトークンを使用したくない理由について誰か提案がありますか? (ええ、昨日は魔法のように機能しました:s)
これが私のトークンを生成する方法です:
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword,
int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
LogonUser(Username, IPMachine, Password,
LOGON32_LOGON_NEW_CREDENTIALS, LOGON32_PROVIDER_DEFAULT,
ref _token);
それは成功したブール値を与えるので、私のトークンには何も問題はないと思います