Some people store the username and password in a config file. Well, you don't need to
You need the “Act as part of operating system” security policy .
You can just call (yes, this is a test):
[TestMethod] public static void SimpleCallAsUser() { string yourUser = @"Someone"; // Change me WindowsIdentity wi = new WindowsIdentity(yourUser); WindowsImpersonationContext imp = wi.Impersonate(); string currentUser = Environment.UserName; Assert.AreEqual(yourUser, currentUser, true, "Could not impersonate"); imp.Undo(); }
If you need to call remote servers or access remote shares, then the account running the code needs delegation configuring. Select the Account in AD and … (Note you do not need todo this if you accessing resources on the Local Machine)
No comments:
Post a Comment