1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

csharp & winServer 2008

Discussion in 'Software Development' started by adam2010, Apr 2, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. adam2010

    adam2010 Thread Starter

    Joined:
    Apr 2, 2010
    Messages:
    6
    Hey all,

    I'm looking for some code (c#) that sets up new a user automatically in WinServer 2008.

    Does someone know such code?

    Where can I find the proper WinServer2008 API for that task?
    or any good tutorial for programming in csharp using windows server 2008 api ?
    (I'm totally new to both csharp and winApi)


    Thanks
     
  2. thingamajig

    thingamajig Banned

    Joined:
    Mar 5, 2005
    Messages:
    6,271
  3. thingamajig

    thingamajig Banned

    Joined:
    Mar 5, 2005
    Messages:
    6,271
    Here is a short code sample from http://www.codeproject.com/KB/system/everythingInAD.aspx

    Code:
    public string CreateUserAccount(string ldapPath, string userName, 
        string userPassword)
    {
        try
        {
            string oGUID = string.Empty;
            string connectionPrefix = "LDAP://" + ldapPath;
            DirectoryEntry dirEntry = new DirectoryEntry(connectionPrefix);
            DirectoryEntry newUser = dirEntry.Children.Add
                ("CN=" + userName, "user");
            newUser.Properties["samAccountName"].Value = userName;
            newUser.CommitChanges();
            oGUID = newUser.Guid.ToString();
    
            newUser.Invoke("SetPassword", new object[] { userPassword });
            newUser.CommitChanges();
            dirEntry.Close();
            newUser.Close();
        }
        catch (System.DirectoryServices.DirectoryServicesCOMException E)
        {
            //DoSomethingwith --> E.Message.ToString();
    
        }
        return oGUID;
    }
    
     
  4. adam2010

    adam2010 Thread Starter

    Joined:
    Apr 2, 2010
    Messages:
    6
    I meant to create local users.
    But I have found the answer already.

    Thanks any way.
     
  5. thingamajig

    thingamajig Banned

    Joined:
    Mar 5, 2005
    Messages:
    6,271
    OK, then I assume you used UserPrincipal and GroupPrincipal objects in the System.DirectoryServices.AccountManagement namespace?
     
  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/914197

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice