M
Mr Cheese
Guest
I am using the code shown below to programmatically add a new Windows user account.
I am having trouble with setting the User account to have the password set to Never Expire.
I have made a few attempts, but I get an exception error "The Parameter is not correct".
Hoping to get some assistance in making this work.
My Code That works:
DirectoryEntry AD = new DirectoryEntry("WinNT://"+Environment.MachineName+",computer");
DirectoryEntry NewUser = AD.Children.Add(Name,"UltimoSecurity");
NewUser.Invoke("SetPassword",new object[] { Pass });
NewUser.Invoke("Put",new object[] { "Description","Ultimo Dental Software Security Account" });
// Would like to add code here to set New User Account so password never expires
NewUser.CommitChanges();
DirectoryEntry grp;
grp=AD.Children.Find("Administrators","group");
if(grp!=null) { grp.Invoke("Add",new object[] { NewUser.Path.ToString() }); }
Code I have tried:
1)
NewUser.Invoke("Put",new object[] { "UserFlags", 0x10000 });
2)
int val = (int)NewUser.Properties["UserFlags"].Value;
NewUser.Properties["UserFlags"].Value=val|0x10000;
I get an exception error "The parameter is not correct".
Thanks for any comments that can help me with this.
Continue reading...
I am having trouble with setting the User account to have the password set to Never Expire.
I have made a few attempts, but I get an exception error "The Parameter is not correct".
Hoping to get some assistance in making this work.
My Code That works:
DirectoryEntry AD = new DirectoryEntry("WinNT://"+Environment.MachineName+",computer");
DirectoryEntry NewUser = AD.Children.Add(Name,"UltimoSecurity");
NewUser.Invoke("SetPassword",new object[] { Pass });
NewUser.Invoke("Put",new object[] { "Description","Ultimo Dental Software Security Account" });
// Would like to add code here to set New User Account so password never expires
NewUser.CommitChanges();
DirectoryEntry grp;
grp=AD.Children.Find("Administrators","group");
if(grp!=null) { grp.Invoke("Add",new object[] { NewUser.Path.ToString() }); }
Code I have tried:
1)
NewUser.Invoke("Put",new object[] { "UserFlags", 0x10000 });
2)
int val = (int)NewUser.Properties["UserFlags"].Value;
NewUser.Properties["UserFlags"].Value=val|0x10000;
I get an exception error "The parameter is not correct".
Thanks for any comments that can help me with this.
Continue reading...