Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than netapi32, prefix the name with the module name and a period.
[StructLayout(LayoutKind.Sequential)]
private struct LOCALGROUP_MEMBERS_INFO_0
{
[MarshalAs(UnmanagedType.SysInt)]
public IntPtr pSID;
}
internal static class Win32ErrorCodes
{
internal const int NERR_Success = 0x000;
// member isn't in the group
internal const int MemberNotInAlias = 0x561;
}
public static bool DelUserFromGroup(string UserName)
{
bool bOk = false;
if (!LookupAccountSid(null, baSid, sbName, ref uiName, sbReferencedDomainName, ref uiReferencedDomainNameCount, out eUse))
return bOk;
// prepare user name
LOCALGROUP_MEMBERS_INFO_3 info;
info.Domain = UserName;
int iRetVal = 0;
if ((iRetVal = NetLocalGroupDelMembers(null, sbName.ToString(), 3, ref info, 1)) != 0)
bOk = true;
return bOk;
}
public static void RemoveFromLocalGroup(string groupName, SecurityIdentifier sid)
{
var sidBytes = new byte[sid.BinaryLength];
sid.GetBinaryForm(sidBytes, 0);
var info = new LOCALGROUP_MEMBERS_INFO_0
{
pSID = Marshal.AllocHGlobal(sidBytes.Length)
};
var result = NetLocalGroupDelMembers(null, groupName, 0, ref info, 1);
if (result == Win32ErrorCodes.NERR_Success || result == Win32ErrorCodes.MemberNotInAlias)
{
return;
}
throw new Win32Exception(result);
}
finally
{
Marshal.FreeHGlobal(info.pSID);
}
}
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).