System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();
Info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
Info.FileName = "net.exe";
Info.Arguments = " user " + username + " " + password + " /add /fullname:\"Internet 的 Guest 帳戶\" /comment:\"匿名存取 Internet Information Services 的內建帳戶\" /passwordchg:no";
System.Diagnostics.Process Proc=new System.Diagnostics.Process();
Proc = System.Diagnostics.Process.Start(Info);请问要怎么样才能让新建的帐户"密码永不过期",不要告诉我在控制面板里面改就是了,我要用代码来实现.请附实现代码,谢谢!
Info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
Info.FileName = "net.exe";
Info.Arguments = " user " + username + " " + password + " /add /fullname:\"Internet 的 Guest 帳戶\" /comment:\"匿名存取 Internet Information Services 的內建帳戶\" /passwordchg:no";
System.Diagnostics.Process Proc=new System.Diagnostics.Process();
Proc = System.Diagnostics.Process.Start(Info);请问要怎么样才能让新建的帐户"密码永不过期",不要告诉我在控制面板里面改就是了,我要用代码来实现.请附实现代码,谢谢!
{
try
{//samName=loginname,
string connectionPrefix = "LDAP://" + parentOUDN;
DirectoryEntry de = new DirectoryEntry(connectionPrefix,"adad","addao" );//adad为超级用户名,addao为密码.如果是本地访问,则可以不需要用户名和密码.
DirectoryEntry newUser = de.Children.Add("CN=" + firstName + " " + lastName, "user");
newUser.Properties["samAccountName"].Value = samName;
newUser.Properties["userPrincipalName"].Value = samName;
newUser.Properties["sn"].Add(lastName);
newUser.Properties["name"].Value = firstName + " " + lastName;
newUser.Properties["displayName"].Value=firstName + lastName;
newUser.Properties["givenName"].Add(firstName);
DateTime dts = DateTime.Now;
//DateTime dts=DateTime.Parse("2008-08-11 17:21:15");
newUser.Properties["userAccountControl"].Value = 0X10000 | 0X0200;
newUser.CommitChanges();
newUser.Invoke("SetPassword", new object[] { userPassword });
newUser.CommitChanges();
de.Close();
newUser.Close();
return true;
}
catch (Exception ex)
{
err = ex.Message;
if (debug)
{
MessageBox.Show("Velde.Utilities.AD.createUserAccount():\n\n" + err);
}
return false;
}
/*
//Add this to the create account method
int val = (int)newUser.Properties["userAccountControl"].Value;
//newUser is DirectoryEntry object
newUser.Properties["userAccountControl"].Value = val | 0x80000;
//ADS_UF_TRUSTED_FOR_DELEGATION
*
* UserAccountControlFlags
* CONST HEX
-------------------------------
SCRIPT 0x0001
ACCOUNTDISABLE 0x0002
HOMEDIR_REQUIRED 0x0008
LOCKOUT 0x0010
PASSWD_NOTREQD 0x0020
PASSWD_CANT_CHANGE 0x0040
ENCRYPTED_TEXT_PWD_ALLOWED 0x0080
TEMP_DUPLICATE_ACCOUNT 0x0100
NORMAL_ACCOUNT 0x0200
INTERDOMAIN_TRUST_ACCOUNT 0x0800
WORKSTATION_TRUST_ACCOUNT 0x1000
SERVER_TRUST_ACCOUNT 0x2000
DONT_EXPIRE_PASSWORD 0x10000
MNS_LOGON_ACCOUNT 0x20000
SMARTCARD_REQUIRED 0x40000
TRUSTED_FOR_DELEGATION 0x80000
NOT_DELEGATED 0x100000
USE_DES_KEY_ONLY 0x200000
DONT_REQ_PREAUTH 0x400000
PASSWORD_EXPIRED 0x800000
TRUSTED_TO_AUTH_FOR_DELEGATION 0x1000000
* */
} //create a user account调用方法为:
bool t5 = ad.createUserAccount("OU=te33fd,DC=BOM,DC=com","kdkeo", "lkdofweorld", "临","时的");
第一个是OU,第二个是登录帐号名,第三个是密码.第四个是姓,第五个名