private SafeLSA_HANDLE GetAccount(string accountName, LsaAccountAccessMask mask = LsaAccountAccessMask.ACCOUNT_VIEW) { var sid = GetSid(accountName); var res = LsaNtStatusToWinError(LsaOpenAccount(Handle, sid, mask, out var hAcct)); if (res == Win32Error.ERROR_FILE_NOT_FOUND) { ThrowIfLsaError(LsaCreateAccount(Handle, sid, mask, out hAcct)); } else { res.ThrowIfFailed(); } return(hAcct); }
private SafeLsaHandle GetAccount(string accountName, LsaAccountAccessMask mask = LsaAccountAccessMask.View) { var sid = GetSid(accountName); SafeLsaHandle hAcct; int res = LsaNtStatusToWinError(LsaOpenAccount(handle, sid, mask, out hAcct)); if (res == 2) { ThrowIfLsaError(LsaCreateAccount(handle, sid, mask, out hAcct)); } else if (res != 0) { throw new ComponentModel.Win32Exception(res); } return(hAcct); }
private SafeLsaPolicyHandle GetAccount(string accountName, LsaAccountAccessMask mask = LsaAccountAccessMask.ACCOUNT_VIEW) { var sid = GetSid(accountName); SafeLsaPolicyHandle hAcct; var res = LsaNtStatusToWinError(LsaOpenAccount(handle, sid, mask, out hAcct)); if (res == Win32Error.ERROR_FILE_NOT_FOUND) { ThrowIfLsaError(LsaCreateAccount(handle, sid, mask, out hAcct)); } else if (res != 0) { Marshal.ThrowExceptionForHR(res); } return(hAcct); }
private static extern int LsaOpenAccount(SafeLsaHandle PolicyHandle, SafeMemoryHandle AccountSid, LsaAccountAccessMask DesiredAccess, out SafeLsaHandle AccountHandle);
public static extern uint LsaOpenAccount(SafeLsaPolicyHandle PolicyHandle, PSID AccountSid, LsaAccountAccessMask DesiredAccess, out SafeLsaPolicyHandle AccountHandle);