Posted on: 11/20/2013 9:21:14 AM | Views : 830

Hello there
Using the following method I impersonate as local administrator user (with elevated privileges) and pass the function that has to be executed within the impersonation context.
/// <summary> /// Attemps to impersonate a given windows user and to run a given function within the impersonation context. /// </summary> /// <param name="userInformation">The user name and password for impersonation.</param> /// <param name="functionAsImpersonatedUser">The function to be executed within the impersonation context.</param> /// <returns>True if the operation was successful, false and an error message otherwise.</returns> public static BooleanResult ExecuteAsImpersonatedUser(UserInformation userInformation, Func<BooleanResult> functionAsImpersonatedUser) { BooleanResult retval = new BooleanResult(); IntPtr returnedToken = ...

Go to the complete details ...