50分太少,不过还是给你一段代码:<br>在NT DOMAIN中添加一用户(其主组为(DOMAIN USER)及一本地组并把用户加入到此组中<br>NET_API_STATUS NetSample( LPWSTR lpszDomain,<br> LPWSTR lpszUser,<br> LPWSTR lpszPassword,<br> LPWSTR lpszLocalGroup )<br>{<br><br> USER_INFO_1 user_info;<br> LOCALGROUP_INFO_1 localgroup_info;<br> LOCALGROUP_MEMBERS_INFO_3 localgroup_members;<br> LPWSTR lpszPrimaryDC = NULL;<br> NET_API_STATUS err = 0;<br> DWORD parm_err = 0;<br><br>/* First get the name of the Primary Domain Controller. */<br>/* Be sure to free the returned buffer */<br><br> err = NetGetDCName( NULL, /* Local Machine */<br> lpszDomain, /* Domain Name */<br> (LPBYTE *)&lpszPrimaryDC ); /* returned PDC */<br><br> if ( err != 0 )<br> {<br> printf( "Error getting DC name: %d/n", err );<br> return( err );<br> }<br><br>/* Set up the USER_INFO_1 struct */<br><br> user_info.usri1_name = lpszUser;<br> user_info.usri1_password = lpszPassword;<br> user_info.usri1_priv = USER_PRIV_USER;<br> user_info.usri1_home_dir =LPWSTR("");<br> user_info.usri1_comment = LPWSTR("Sample User");<br> user_info.usri1_flags = UF_SCRIPT;<br> user_info.usri1_script_path = LPWSTR("");<br><br> err = NetUserAdd( lpszPrimaryDC, /* PDC name */<br> 1, /* level */<br> (LPBYTE)&user_info, /* input buffer */<br> &parm_err ); /* parameter in error */<br><br> switch ( err )<br> {<br> case 0:<br> printf("user successfully created./n");<br> break;<br> case NERR_UserExists:<br> printf("user already exists./n");<br> err = 0;<br> break;<br> case ERROR_INVALID_PARAMETER:<br> printf("Invalid Parameter Error adding user
arameter Index = %d/n",<br> parm_err);<br> NetApiBufferFree( lpszPrimaryDC ); return( err );<br> default:<br> printf("Error adding user: %d/n", err);<br> NetApiBufferFree( lpszPrimaryDC );<br> return( err );<br> }<br><br>/* Set up the LOCALGROUP_INFO_1 struct */<br><br> localgroup_info.lgrpi1_name = lpszLocalGroup;<br> localgroup_info.lgrpi1_comment =LPWSTR("Sample Local group.");<br><br> err = NetLocalGroupAdd( lpszPrimaryDC, /* PDC name */<br> 1, /* level */<br> (LPBYTE)&localgroup_info, /* input buffer */<br> &parm_err ); /* parm in error */<br><br> switch ( err )<br> {<br> case 0:<br> printf("Local Group successfully created./n");<br> break;<br> case ERROR_ALIAS_EXISTS:<br> printf("Local Group already exists./n");<br> err = 0;<br> break;<br> case ERROR_INVALID_PARAMETER:<br> printf("Invalid Parameter Error adding Local Group
arameter Index = %d/n",<br> err, parm_err);<br> NetApiBufferFree( lpszPrimaryDC );<br> return( err );<br> default:<br> printf("Error adding Local Group: %d/n", err);<br> NetApiBufferFree( lpszPrimaryDC );<br> return( err );<br> }<br><br>/* Now add the user to the local group */<br><br> localgroup_members.lgrmi3_domainandname = lpszUser;<br><br> err = NetLocalGroupAddMembers( lpszPrimaryDC, /* PDC name */<br> lpszLocalGroup, /* group name */<br> 3, /* passing in name */<br> (LPBYTE)&localgroup_members, /* Buffer */<br> 1 ); /* count passed in */<br><br> switch ( err )<br> {<br> case 0:<br> printf("User successfully added to Local Group./n");<br> break;<br> case ERROR_MEMBER_IN_ALIAS:<br> printf("User already in Local Group./n");<br> err = 0;<br> break;<br> default:<br> printf("Error adding User to Local Group: %d/n", err);<br> break;<br> }<br><br> NetApiBufferFree( lpszPrimaryDC );<br> return( err );<br>}<br><br>