using namespace System;
using namespace System::DirectoryServices;
// This is the entry point for this application.
int _tmain(void)
{
try
{
//Build the path, and then bind to computer.
String *adsPath = String::Format(S"WinNT://{0},computer", Environment::MachineName);
DirectoryEntry *computerEntry = new DirectoryEntry(adsPath);
DirectoryEntry *userEntry = computerEntry->Children->Add(S"TestUser1", S"user");
userEntry->Properties->get_Item(S"Description")->Add(S"Test user from .NET");
//Set the password, and then commit the changes.
String *stringArray[] = new String *[1];
stringArray[0] = S"#12353Abc";
userEntry->Invoke(S"SetPassword", stringArray);
userEntry->CommitChanges();
//Add the new user to a group.
DirectoryEntry *groupEntry = computerEntry->Children->Find(S"Administrators");
stringArray[0] = userEntry->Path;
groupEntry->Invoke(S"Add", stringArray);
}
catch(Exception *e)
{
Console::WriteLine(e);
}