Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Creat New Security Group At AD

Creat New Security Group At AD

Scheduled Pinned Locked Moved C#
csharpcomwindows-adminsecurityhelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    treuveni
    wrote on last edited by
    #1

    Hi, I'm trying to add new group, but getting an error: error (0x80005000) this is my code- /// <summary> /// Creates a new group in Active Directory /// </summary> /// <param name="sOU">The OU location you want to save your new Group</param> /// <param name="sGroupName">The name of the new group</param> /// <param name="sDescription">The description of the new group</param> /// <param name="oGroupScope">The scope of the new group</param> /// <param name="bSecurityGroup">True is you want this group /// to be a security group, false if you want this as a distribution group</param> /// <returns>Returns the GroupPrincipal object</returns> public GroupPrincipal CreateNewGroup(string sOU, string sGroupName, string sDescription, GroupScope oGroupScope, bool bSecurityGroup) { PrincipalContext oPrincipalContext = GetPrincipalContext(sOU); GroupPrincipal oGroupPrincipal = new GroupPrincipal(oPrincipalContext, sGroupName); oGroupPrincipal.Description = sDescription; oGroupPrincipal.GroupScope = oGroupScope; oGroupPrincipal.IsSecurityGroup = bSecurityGroup; oGroupPrincipal.Save(); return oGroupPrincipal; } /// <summary> /// Gets the principal context on specified OU /// </summary> /// <param name="sOU">The OU you want your Principal Context to run on</param> /// <returns>Returns the PrincipalContext object</returns> public PrincipalContext GetPrincipalContext(string sOU) { PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, sDomain, sOU, ContextOptions.SimpleBind, sServiceUser, sServicePassword); return oPrincipalContext; } The code thaken from here- Everything in Active Directory via C#.NET 3.5 (Using System.DirectoryServices.AccountManagement)[^] i think the error comming from here- GroupPrincipal oGroupPrincipal = new GroupPrincipal(oPrincipalContext, sGroupName); what i'm doing wrong? :(

    L D 2 Replies Last reply
    0
    • T treuveni

      Hi, I'm trying to add new group, but getting an error: error (0x80005000) this is my code- /// <summary> /// Creates a new group in Active Directory /// </summary> /// <param name="sOU">The OU location you want to save your new Group</param> /// <param name="sGroupName">The name of the new group</param> /// <param name="sDescription">The description of the new group</param> /// <param name="oGroupScope">The scope of the new group</param> /// <param name="bSecurityGroup">True is you want this group /// to be a security group, false if you want this as a distribution group</param> /// <returns>Returns the GroupPrincipal object</returns> public GroupPrincipal CreateNewGroup(string sOU, string sGroupName, string sDescription, GroupScope oGroupScope, bool bSecurityGroup) { PrincipalContext oPrincipalContext = GetPrincipalContext(sOU); GroupPrincipal oGroupPrincipal = new GroupPrincipal(oPrincipalContext, sGroupName); oGroupPrincipal.Description = sDescription; oGroupPrincipal.GroupScope = oGroupScope; oGroupPrincipal.IsSecurityGroup = bSecurityGroup; oGroupPrincipal.Save(); return oGroupPrincipal; } /// <summary> /// Gets the principal context on specified OU /// </summary> /// <param name="sOU">The OU you want your Principal Context to run on</param> /// <returns>Returns the PrincipalContext object</returns> public PrincipalContext GetPrincipalContext(string sOU) { PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, sDomain, sOU, ContextOptions.SimpleBind, sServiceUser, sServicePassword); return oPrincipalContext; } The code thaken from here- Everything in Active Directory via C#.NET 3.5 (Using System.DirectoryServices.AccountManagement)[^] i think the error comming from here- GroupPrincipal oGroupPrincipal = new GroupPrincipal(oPrincipalContext, sGroupName); what i'm doing wrong? :(

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You should have received an associated error message. Post it here.

      T 1 Reply Last reply
      0
      • L Lost User

        You should have received an associated error message. Post it here.

        T Offline
        T Offline
        treuveni
        wrote on last edited by
        #3

        System.DirectoryServices.AccountManagement.PrincipalOperationException was caught Message=Unknown error (0x80005000) Source=System.DirectoryServices.AccountManagement ErrorCode=-2147463168

        L 1 Reply Last reply
        0
        • T treuveni

          Hi, I'm trying to add new group, but getting an error: error (0x80005000) this is my code- /// <summary> /// Creates a new group in Active Directory /// </summary> /// <param name="sOU">The OU location you want to save your new Group</param> /// <param name="sGroupName">The name of the new group</param> /// <param name="sDescription">The description of the new group</param> /// <param name="oGroupScope">The scope of the new group</param> /// <param name="bSecurityGroup">True is you want this group /// to be a security group, false if you want this as a distribution group</param> /// <returns>Returns the GroupPrincipal object</returns> public GroupPrincipal CreateNewGroup(string sOU, string sGroupName, string sDescription, GroupScope oGroupScope, bool bSecurityGroup) { PrincipalContext oPrincipalContext = GetPrincipalContext(sOU); GroupPrincipal oGroupPrincipal = new GroupPrincipal(oPrincipalContext, sGroupName); oGroupPrincipal.Description = sDescription; oGroupPrincipal.GroupScope = oGroupScope; oGroupPrincipal.IsSecurityGroup = bSecurityGroup; oGroupPrincipal.Save(); return oGroupPrincipal; } /// <summary> /// Gets the principal context on specified OU /// </summary> /// <param name="sOU">The OU you want your Principal Context to run on</param> /// <returns>Returns the PrincipalContext object</returns> public PrincipalContext GetPrincipalContext(string sOU) { PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, sDomain, sOU, ContextOptions.SimpleBind, sServiceUser, sServicePassword); return oPrincipalContext; } The code thaken from here- Everything in Active Directory via C#.NET 3.5 (Using System.DirectoryServices.AccountManagement)[^] i think the error comming from here- GroupPrincipal oGroupPrincipal = new GroupPrincipal(oPrincipalContext, sGroupName); what i'm doing wrong? :(

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Chances are you passed in an invalid ADS pathname to one of your functions.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak

          T 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Chances are you passed in an invalid ADS pathname to one of your functions.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            T Offline
            T Offline
            treuveni
            wrote on last edited by
            #5

            nope, all of them ar currect

            1 Reply Last reply
            0
            • T treuveni

              System.DirectoryServices.AccountManagement.PrincipalOperationException was caught Message=Unknown error (0x80005000) Source=System.DirectoryServices.AccountManagement ErrorCode=-2147463168

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              This[^] discussion seems to be related to your problem.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups