csharp & winServer 2008

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

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
 

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

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.
 

thingamajig

Banned
Joined
Mar 5, 2005
Messages
6,271
I meant to create local users.
But I have found the answer already.

Thanks any way.
OK, then I assume you used UserPrincipal and GroupPrincipal objects in the System.DirectoryServices.AccountManagement namespace?
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Latest posts

Members online

Top