Create if a company intends to use Microsoft's products to build its own office automation system, then it is recommended to use the primary domain control approach. Then, the Active Directory (AD) must be used, so that the IT department needs to create a domain account for each employee of the company. If the company is big, this is a very big project. And, we will find that some of the workload is basically duplication of labor, the Human resources department in order to give IT departments to provide a list of personnel, will input a variety of information, such as name, work number, department, department leader, telephone number, etc., then the IT staff in the form, he has to re-enter again. And often causes errors in the account for human reasons. Below, we wrote a program to create an account in C #. In this program, not only does it create a domain account, it also creates a corresponding mail account in the appropriate exchange. With this program, the HR department only needs to fill in the relevant projects in the database format (Access) provided by the IT department.
First, we need to define some variables:
String strmemberof= "";
String Struserparm= "";
String Strmanager= "";
String Strscriptpath= "";
String Strdepartment= "";
String Strcompany= "";
String Straccountexp;
String DEFAULTNC = "Dc=test,dc=net"; This is the default domain
String alias = "";
String fullName = "";
string password = @ "password"; This is the default initial password
string domainname = "Test.net";
String Strgivenname= "";
The following variable tells the program where to build the mailbox in which storage area of exchange
String HomeMDB = "cn=test,cn= Holding company,"
+ "Cn=informationstore,cn=mail,cn=servers,"
+ "Cn=first administrative group,cn=administrative Groups,"
+ "Cn=test,cn=microsoft exchange,cn=services,"
+ "Cn=configuration,dc=test,dc=net";
Label1. text= "Start loading data from the template!" ";
Get template information
We know that many of the items created in the account are the same, so we first create an account as a template, and then, by reading the template's data as the corresponding item for the new account.
This code uses the query object for AD:
DirectoryEntry DEMB = new DirectoryEntry ();
Demb.path= "ldap://cn= template, ou= project team, ou= Department, Dc=test, Dc=net";
strmemberof=demb.properties["memberof"][0]. ToString ();
struserparm=demb.properties["Userparameters"][0]. ToString ();
strmanager=demb.properties["Manager"][0]. ToString ();
strscriptpath=demb.properties["ScriptPath"][0]. ToString ();
strdepartment=demb.properties["department"][0]. ToString ();
Strcompany=demb.properties["Company"][0]. ToString ();
straccountexp=demb.properties["Accountexpires"]. Value.tostring ();
Demb.close ();
Label1. text= "Load data complete!" Start reading new account information from the database! ";
Read database get account information
ADODB. Connection objconn;
Adodb.command objcmd;
ADODB. Recordset objRS;
Object Objoptparm;
Objoptparm= "";
String str=@ "Jet oledb:global Partial Bulk ops=2; Jet Oledb:registry path=; Jet oledb:database locking Mode=1;data source= "Db1.mdb"; Mode=share Deny None; Jet Oledb:engine type=5; Provider= "" Microsoft.Jet.OLEDB.4.0 ""; Jet Oledb:system database=; Jet oledb:sfp=false;persist Security Info=false; Extended properties=; Jet oledb:compact without Replica repair=false; Jet Oledb:encrypt Database=false; Jet oledb:create System Database=false; Jet Oledb:don ' t Copy Locale on Compact=false; User id=admin; Jet oledb:global Bulk Transactions=1 ";
Objconn=new ADODB. Connection ();
Try
{
objConn.Open (str, "", "" ",-1);
Here is to explain: this is to set the account expiration time, because, according to our rules, if the account expires before the test, then the account will be disabled. However, the ad in this field is plastic, I do not know how to convert it, so there is the following code, hope, have a master can be pointing.
DateTime dt=new datetime (2004,10,31,0,0,0,0);
Long Longae=dt. Ticks;
longae=longae-504910656000000000;//minus 8 time zones
User. properties["Accountexpires"]. ADD (Longae.tostring ());//Account Expiration time
User. Invoke ("SetPassword", New Object[]{password});
User.commitchanges ();
User. Invoke ("SetPassword", New Object[]{password});
User.commitchanges ();
This enables the new user.
User. properties["userAccountControl"]. Value = 0x200; Ads_uf_normal_account
User.commitchanges ();
Obtain the IMailboxStore interface, create the mailbox, and commit the changes.
Mailbox = (imailboxstore) user. NativeObject;
Mailbox. CreateMailbox (HomeMDB);
User.commitchanges ();
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.