如何在用户管理中加入用户(FOR WINDOWS NT4.0)(50分)

  • 主题发起人 主题发起人 HEPAM
  • 开始时间 开始时间
H

HEPAM

Unregistered / Unconfirmed
GUEST, unregistred user!
我想在程序中直接加入网络用户,如何编程?
 
注册表里肯定有,自己查吧。
 
查看“Windows库函数”一书,可能对你有帮助。
 
得了 NT SET 可以修改用户列表
 
50分太少,不过还是给你一段代码:<br>在NT DOMAIN中添加一用户(其主组为(DOMAIN USER)及一本地组并把用户加入到此组中<br>NET_API_STATUS NetSample( LPWSTR lpszDomain,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPWSTR lpszUser,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPWSTR lpszPassword,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LPWSTR lpszLocalGroup )<br>{<br><br>&nbsp; &nbsp; USER_INFO_1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user_info;<br>&nbsp; &nbsp; LOCALGROUP_INFO_1 &nbsp; &nbsp; &nbsp; &nbsp; localgroup_info;<br>&nbsp; &nbsp; LOCALGROUP_MEMBERS_INFO_3 localgroup_members;<br>&nbsp; &nbsp; LPWSTR &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lpszPrimaryDC = NULL;<br>&nbsp; &nbsp; NET_API_STATUS &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;err = 0;<br>&nbsp; &nbsp; DWORD &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parm_err = 0;<br><br>/* First get the name of the Primary Domain Controller. */<br>/* Be sure to free the returned buffer */<br><br>&nbsp; &nbsp; err = NetGetDCName( NULL, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* Local Machine */<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lpszDomain, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* Domain Name */<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(LPBYTE *)&amp;lpszPrimaryDC ); &nbsp;/* returned PDC */<br><br>&nbsp; &nbsp; if ( err != 0 )<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; printf( "Error getting DC name: %d/n", err );<br>&nbsp; &nbsp; &nbsp; &nbsp; return( err );<br>&nbsp; &nbsp; }<br><br>/* Set up the USER_INFO_1 struct */<br><br>&nbsp; &nbsp; user_info.usri1_name = lpszUser;<br>&nbsp; &nbsp; user_info.usri1_password = lpszPassword;<br>&nbsp; &nbsp; user_info.usri1_priv = USER_PRIV_USER;<br>&nbsp; &nbsp; user_info.usri1_home_dir =LPWSTR("");<br>&nbsp; &nbsp; user_info.usri1_comment = LPWSTR("Sample User");<br>&nbsp; &nbsp; user_info.usri1_flags = UF_SCRIPT;<br>&nbsp; &nbsp; user_info.usri1_script_path = LPWSTR("");<br><br>&nbsp; &nbsp; err = NetUserAdd( lpszPrimaryDC, &nbsp; &nbsp; &nbsp; /* PDC name */<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* level */<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (LPBYTE)&amp;user_info, &nbsp;/* input buffer */<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;parm_err ); &nbsp; &nbsp; &nbsp; &nbsp; /* parameter in error */<br><br>&nbsp; &nbsp; switch ( err )<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; case 0:<br>&nbsp; &nbsp; &nbsp; &nbsp; printf("user successfully created./n");<br>&nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; case NERR_UserExists:<br>&nbsp; &nbsp; &nbsp; &nbsp; printf("user already exists./n");<br>&nbsp; &nbsp; &nbsp; &nbsp; err = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; case ERROR_INVALID_PARAMETER:<br>&nbsp; &nbsp; &nbsp; &nbsp; printf("Invalid Parameter Error adding user:Parameter Index = %d/n",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parm_err);<br>&nbsp; &nbsp; &nbsp; &nbsp; NetApiBufferFree( lpszPrimaryDC ); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return( err );<br>&nbsp; &nbsp; default:<br>&nbsp; &nbsp; &nbsp; &nbsp; printf("Error adding user: %d/n", err);<br>&nbsp; &nbsp; &nbsp; &nbsp; NetApiBufferFree( lpszPrimaryDC );<br>&nbsp; &nbsp; &nbsp; &nbsp; return( err );<br>&nbsp; &nbsp; }<br><br>/* Set up the LOCALGROUP_INFO_1 struct */<br><br>&nbsp; &nbsp; localgroup_info.lgrpi1_name = lpszLocalGroup;<br>&nbsp; &nbsp; localgroup_info.lgrpi1_comment =LPWSTR("Sample Local group.");<br><br>&nbsp; &nbsp; err = NetLocalGroupAdd( lpszPrimaryDC, &nbsp; &nbsp;/* PDC name */<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* level */<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (LPBYTE)&amp;localgroup_info, &nbsp; /* input buffer */<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;parm_err ); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* parm in error */<br><br>&nbsp; &nbsp; switch ( err )<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; case 0:<br>&nbsp; &nbsp; &nbsp; &nbsp; printf("Local Group successfully created./n");<br>&nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; case ERROR_ALIAS_EXISTS:<br>&nbsp; &nbsp; &nbsp; &nbsp; printf("Local Group already exists./n");<br>&nbsp; &nbsp; &nbsp; &nbsp; err = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; case ERROR_INVALID_PARAMETER:<br>&nbsp; &nbsp; &nbsp; &nbsp; printf("Invalid Parameter Error adding Local Group:Parameter Index = %d/n",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; err, parm_err);<br>&nbsp; &nbsp; &nbsp; &nbsp; NetApiBufferFree( lpszPrimaryDC );<br>&nbsp; &nbsp; &nbsp; &nbsp; return( err );<br>&nbsp; &nbsp; default:<br>&nbsp; &nbsp; &nbsp; &nbsp; printf("Error adding Local Group: %d/n", err);<br>&nbsp; &nbsp; &nbsp; &nbsp; NetApiBufferFree( lpszPrimaryDC );<br>&nbsp; &nbsp; &nbsp; &nbsp; return( err );<br>&nbsp; &nbsp; }<br><br>/* Now add the user to the local group */<br><br>&nbsp; &nbsp; localgroup_members.lgrmi3_domainandname = lpszUser;<br><br>&nbsp; &nbsp; err = NetLocalGroupAddMembers( lpszPrimaryDC, &nbsp; &nbsp; /* PDC name */<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lpszLocalGroup, &nbsp; &nbsp;/* group name */<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* passing in name */<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(LPBYTE)&amp;localgroup_members, /* Buffer */<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1 ); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/* count passed in */<br><br>&nbsp; &nbsp; switch ( err )<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; case 0:<br>&nbsp; &nbsp; &nbsp; &nbsp; printf("User successfully added to Local Group./n");<br>&nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; case ERROR_MEMBER_IN_ALIAS:<br>&nbsp; &nbsp; &nbsp; &nbsp; printf("User already in Local Group./n");<br>&nbsp; &nbsp; &nbsp; &nbsp; err = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; default:<br>&nbsp; &nbsp; &nbsp; &nbsp; printf("Error adding User to Local Group: %d/n", err);<br>&nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; }<br><br>&nbsp; &nbsp; NetApiBufferFree( lpszPrimaryDC );<br>&nbsp; &nbsp; return( err );<br>}<br><br>
 
这是VC版的,转化成C++BUILDER或DELPHI的就可以了,本人测试通过。<br>只能在NT下运行噢。
 
还不加分?
 
这个问题还没结束,加点分我把C++BUILDER的代码帖出来。
 
太麻烦。<br>你可以用Netuseradd,Netuserdel,Netuserchangepassword.......等等修改用户。<br>Netgroupadduser.netgroupdeluser.....等等修改用户组属性。<br>Netgroupadd.Netgroupdel...等等修改组。。<br>太多啦。<br><br>函数库:netapi32.lib
 
接受答案了.
 
后退
顶部