Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
netlocalgroupdelmembers (netapi32)
 
.
Summary
removes one or more members from an existing local group

C# Signature:

    [DllImport("NetApi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    static extern Int32 NetLocalGroupDelMembers(
        string servername,
        string groupname,
        UInt32 level,
        ref LOCALGROUP_MEMBERS_INFO_3 buf,
        UInt32 totalentries
        );

VB Signature:

Declare Function NetLocalGroupDelMembers Lib "netapi32.dll" (TODO) As TODO

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

        struct LOCALGROUP_MEMBERS_INFO_3
        {
            [MarshalAs(UnmanagedType.LPWStr)]
            public string Domain;
        }

        [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        static extern bool LookupAccountSid(
            string SystemName,
            [MarshalAs(UnmanagedType.LPArray)] byte[] Sid,
            StringBuilder Name,
            ref uint NameCount,
            StringBuilder ReferencedDomainName,
            ref uint ReferencedDomainNameCount,
            out SID_NAME_USE SIDUse);

        public static bool DelUserFromGroup(string UserName)
        {
            bool bOk = false;

            StringBuilder sbName = new StringBuilder();
            uint uiName = (uint)sbName.Capacity;
            StringBuilder sbReferencedDomainName = new StringBuilder();
            uint uiReferencedDomainNameCount = (uint)sbReferencedDomainName.Capacity;
            SID_NAME_USE eUse;
            // Sid for BUILTIN\Administrators
            byte[] baSid = new byte[] { 1, 2, 0, 0, 0, 0, 0, 5, 32, 0, 0, 0, 32, 2 };

            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;
        }

Documentation

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).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions