Example #1
0
 public static void RevertToSelf()
 {
     if (!LogonAPI.RevertToSelf())
     {
         throw new Exception("RevertToSelf failed.");
     }
 }
Example #2
0
        public static WindowsPrincipal GetLogonUser(
            string domain, string userName, string password)
        {
            IIdentity        user      = null;
            WindowsPrincipal principal = null;
            IntPtr           refToken  = IntPtr.Zero;
            bool             loggedIn;

            RevertToSelf();

            loggedIn =
                LogonAPI.LogonUser(userName, domain, password,
                                   LogonAPI.LOGON32_LOGON_NETWORK_CLEARTEXT,
                                   LogonAPI.LOGON32_PROVIDER_DEFAULT, ref refToken);

            if (loggedIn == true)
            {
                user      = new WindowsIdentity(refToken, "NTLM", WindowsAccountType.Normal, true);
                principal = new WindowsPrincipal(user as WindowsIdentity);
            }

            return(principal);
        }