| 发表于:2007-06-05 10:53:134楼 得分:10 |
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.text; using system.windows.forms; using system.directoryservices; namespace windowsapplication29 { public partial class form1 : form { public form1() { initializecomponent(); } private void button1_click(object sender, eventargs e) { try { directoryentry ad = new directoryentry( "winnt:// " + environment.machinename + ",computer "); directoryentry newuser = ad.children.add( "testuser1 ", "user "); newuser.invoke( "setpassword ", new object[] { "#12345abc " }); newuser.invoke( "put ", new object[] { "description ", "test user from .net " }); newuser.commitchanges(); directoryentry grp; grp = ad.children.find( "guests ", "group "); if (grp != null) { grp.invoke( "add ", new object[] { newuser.path.tostring() }); } console.writeline( "account created successfully "); console.readline(); } catch (exception ex) { console.writeline(ex.message); console.readline(); } } } } | | |
|