private void LoadUserDomainValues(StringBuilder principalName) { StringBuilder user = new StringBuilder(Win32Native.CREDUI_MAX_USERNAME_LENGTH); StringBuilder domain = new StringBuilder(Win32Native.CREDUI_MAX_DOMAIN_TARGET_LENGTH); Win32Native.CredUIReturnCodes result = Win32Native.CredUIParseUserNameW(principalName.ToString(), user, Win32Native.CREDUI_MAX_USERNAME_LENGTH, domain, Win32Native.CREDUI_MAX_DOMAIN_TARGET_LENGTH); if (result == Win32Native.CredUIReturnCodes.NO_ERROR) { User = user.ToString(); if (User != "MiAdmin") { Domain = domain.ToString(); } } else { throw new InvalidOperationException(TranslateReturnCode(result)); //User = principalName.ToString(); //if (User != "MiAdmin") // Domain = Environment.UserDomainName; //else // Domain = string.Empty; } }
private void LoadUserDomainValues(StringBuilder principalName) { var user = new StringBuilder(Win32Native.CREDUI_MAX_USERNAME_LENGTH); var domain = new StringBuilder(Win32Native.CREDUI_MAX_DOMAIN_TARGET_LENGTH); var result = Win32Native.CredUIParseUserNameW(principalName.ToString(), user, Win32Native.CREDUI_MAX_USERNAME_LENGTH, domain, Win32Native.CREDUI_MAX_DOMAIN_TARGET_LENGTH); if (result == Win32Native.CredUIReturnCodes.NO_ERROR) { User = user.ToString(); Domain = domain.ToString(); } else { User = principalName.ToString(); Domain = Environment.MachineName; } }