When I concatenated the two flags with: int iUserAccountControl =
ADS_USER_FLAG.ADS_UF_DONT_EXPIRE_PASSWD
+ ADS_USER_FLAG.ADS_UF_PASSWD_CANT_CHANGE; I received the following build
error: Operator '+' cannot be applied to operands of type
'ActiveDs.ADS_USER_FLAG' and 'ActiveDs.ADS_USER_FLAG'
I tried to ‘OR†the statement int iUserAccountControl =
ADS_USER_FLAG.ADS_UF_DONT_EXPIRE_PASSWD
| ADS_USER_FLAG.ADS_UF_PASSWD_CANT_CHANGE; but received the following build
error: Cannot implicitly convert type 'ActiveDs.ADS_USER_FLAG' to 'int'
It seems that the ADS_USER_FLAG needed a reference to the COM ActiveDs.dll.
Listed below is the program is its totality.
using System;
using System.DirectoryServices;
using ActiveDs;
namespace ConsoleApplication3
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
try
{
string path = "LDAP://ec-t1/CN=Users,DC=smallbusiness,DC=local";
DirectoryEntry entry = new DirectoryEntry(path,"ec=t1\\administrator",
"mae008");
DirectoryEntry newUser = entry.Children.Add("cn=Test User", "user");
newUser.Properties["sAMAccountName"].Add("testuser");
newUser.Properties["userPrincipalName"].Add("testuser");
newUser.Properties["sn"].Add("User");
newUser.Properties["givenName"].Add("Test");
newUser.Properties["description"].Add("Test account added with code.");
newUser.Properties["displayname"].Add("Test");
newUser.Properties["physicalDeliveryOfficeName"].Add("Test");
newUser.CommitChanges();
newUser.Invoke("SetPassword", new object[] {"mypassword1"} );
//int iUserAccountControl = ADS_USER_FLAG.ADS_UF_DONT_EXPIRE_PASSWD +
ADS_USER_FLAG.ADS_UF_PASSWD_CANT_CHANGE;
int iUserAccountControl = ADS_USER_FLAG.ADS_UF_DONT_EXPIRE_PASSWD
| ADS_USER_FLAG.ADS_UF_PASSWD_CANT_CHANGE;
newUser.Properties["userAccountControl"].Value = iUserAccountControl;
newUser.CommitChanges();
}
catch( Exception exception )
{
Console.WriteLine( exception.Message );
}
}
}
}
If I can ever help you in return for the all help you have given me, just
say the word.
Thanks,
Mark
Marc Scheuner said:
I found reference to userAccountControl and the corresponding account options for User Cannot
Change Password & Password Never Expires, but I find I could get the syntax right.
Sure - given that you have a DirectoryEntry called "newUser" from
previous code, do this:
int iUserAccountControl = ADS_USER_FLAG.ADS_UF_DONT_EXPIRE_PASSWD +
ADS_USER_FLAG.ADS_UF_PASSWD_CANT_CHANGE;
oNewUser.Properties["uSerAccountControl"].Value = iUserAccountControl;
oNewUser.CommitChanges();
Hope this helps
Marc
================================================================
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch