public void AddPrivilege(string account, string privilege)
{
IntPtr pSid = GetSIDInformation(account);
LSA_UNICODE_STRING[] privileges = new LSA_UNICODE_STRING[1];
privileges[0] = InitLsaString(privilege);
long ret = LsaAddAccountRights(lsaHandle, pSid, privileges, 1);
if (ret != 0)//ret = 0 Success
{
if (ret == STATUS_ACCESS_DENIED)
throw new UnauthorizedAccessException();
if ((ret == STATUS_INSUFFICIENT_RESOURCES) || (ret == STATUS_NO_MEMORY))
throw new OutOfMemoryException();
throw new Win32Exception((int)LsaNtStatusToWinError((int)ret));
}
}