Hi all,
Was wondering if anybody has expericence this problem..
I am writting an application in C# using windows forms, to create windows
user profiles and then updating the registry information for the new
profiles.
I have managed to create the user successfully and thought that I was
writting the registry information correctly.
That was until I checked the 'C:\Documents and Settings' Directory, when I
noticed that the new users directories did not reflect their names. But
instead comprised of non printable characters!!!
Here is the code sample in C#
DirectoryEntry NewUser;
DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName
+ ",computer");
// delete user when existing
try
{
// this throws when no such user
NewUser = AD.Children.Find(strNodeName, "User");
MessageBox.Show("User already exists!!");
return;
}// Catch not found exception
catch(COMException cex)
{
Console.WriteLine(cex.Message);
}
// Add user using the user schema
NewUser = AD.Children.Add(strNodeName, "user");
NewUser.Properties["description"].Add(this.txtFirstName.Text + " " +
this.txtSurname.Text);
// NewUser.Properties["PasswordExpired"].Add(1); // user must change
password at next login
// Set user flags sample here sets Account disabled, pwd can't change
// this flag is different for LDAP accounts
NewUser.Properties["userFlags"].Add( UF_NORMAL_ACCOUNT |
UF_DONT_EXPIRE_PASSWD );
// invoke native method 'SetPassword' before commiting
// for AD domain accounts this must be done after commiting
NewUser.Invoke("SetPassword", new Object[] { this.txtPassword.Text });
NewUser.CommitChanges();
foreach(string s in NewUser.Properties.PropertyNames)
Console.WriteLine(s + " " + (NewUser.Properties[s])[0]);
// Add user to guests alias
DirectoryEntry grp = AD.Children.Find("Guests", "group");
if(grp.Name != null)
{
grp.Invoke("Add", new Object[] {NewUser.Path.ToString()});
}
MessageBox.Show("Account Created Successfully");
AD.Close();