Use NetAPI32 calls to power a GUI utility for adding users to a domain en masse
Suppose you're getting ready to leave work at 4:30 p.m. and your boss stops by your office and says, "I need you to create 50 user accounts by tomorrow at 8:00 a.m." To create large groups of users on a tight deadline, you can use various Perl scripts or Microsoft Windows NT Server 4.0 Resource Kit utilities. (For information about these scripts and utilities, see Mark Minasi, "Netdom's Member Option," May 1999, and "AddUsers," May 1998, and Michael D. Reilly, "NET Commands," November 1997.)
Unlike Windows Scripting Host (WSH) scripts, Perl scripts, and resource kit utilities, Visual Basic (VB) lets you quickly and easily create a GUI with the same look and feel as NT's User Manager. I used VB to write a user-creation utility that I call Bulk User Create (BUC). I designed BUC to add user accounts to a PDC's accounts database. The utility doesn't recognize group memberships; user accounts you add through BUC appear in only the Domain Users group. You can run BUC from any NT machine in the same domain as the PDC you want to add user accounts to. However, the utility passes to the PDC in clear text the user account information you supply. If you run the utility on a remote system, the username and password travel across the network, and a network sniffer might intercept them. You must determine the risk of this occurrence and take the appropriate action to prevent it (e.g., run BUC on the PDC).
BUC uses netapi32.dll functions to perform the core of its work. These functions let you obtain template account information, determine the name of the domain's PDC, and add users. For information about other components of BUC's code, see the sidebar "Additional BUC Components."
Using BUC
BUC demonstrates how you can use NetAPI32 calls in a VB application. The utility lets you enter in text boxes information for user accounts you want to add, then builds a list of the user accounts. When you start BUC, the WinNT Magazine Bulk User Create dialog box, which Screen 1 shows, opens. In this main window, you enter values for the User Name, Full Name, and User Password parameters for each account. After you enter information in a field, you can tab to the next field. After you enter the necessary information for one account, tab to Add and press Enter. Then, tab to Add Users and press Enter to add the user account to the accounts database, or tab past Add Users to User Name and enter another user account. I set the User Name, Full Name, User Password, and Confirm Password fields and the Add and Add Users buttons as tab stops so that you can easily add users. Tab stops don't work for other controls in the main window, but you can left-click to select any of the options. If you enter only the User Name, Full Name, and User Password parameters for an account, BUC sets the account's other parameters to the defaults in Table 1.
You can specify additional account parameters (i.e., Description, User Profile, Logon Script, Home Drive, and Home Path) and select password options in BUC's Advanced User Create Options dialog box, which Screen 2, page 118, shows. To reach this dialog box, select the Use Advanced User Options check box in the WinNT Magazine Bulk User Create dialog box to enable the Set User Options button. Click Set User Options to open the Advanced User Create Options dialog box.
If you want to specify account parameters that the Advanced User Create Options dialog box doesn't offer, you can specify a template account for BUC to copy. If you use a template, BUC ensures that new users' profiles match the template, except for User Name, Full Name, and User Password. To use a template, select the Use Template Account check box in the advanced options screen. Specify the account you want to use in the Use Template Account text box. Then, click Get Info to fill in the new account with values from the template account. You can change the template's parameters by entering values in the advanced options screen's text boxes.
The advanced and template options let you save settings as the default for new users. The Save Settings As Default check box on the advanced options screen lets you specify whether BUC saves the settings you configure or uses them for only the current session. If you select this check box, the utility saves the values in the HKEY_LOCAL_MACHINE\ SOFTWARE\WinNTMag\BUC Registry key. When you finish configuring options, click Done to return to the main screen. If you click Cancel, you'll return to the main screen, but the utility won't retain the settings you configured.
After you specify the values for all the user accounts you want to add, click Add Users on the main screen to add all the user accounts to the PDC's accounts database using the values you entered. If an error occurs during the user-addition process, the program pauses and asks you whether you want to continue adding user accounts or stop the process. The utility sends a pop-up window that tells you it successfully added all the user accounts.
You must be a member of the Account Operators or Administrators group on the PDC to run BUC or use its underlying functions. BUC requires no additional software beyond the VB 5.0 runtime modules.
Prev. page  
[1]
2
3
next page