Listing 1: CheckNCreateUser.vbs # BEGIN CALLOUT A Sub QueryForUser Dim oUser, oDomain BEGIN COMMENT ' Connect to the appropriate domain and collect all the ‘ user accounts in it. END COMMENT Set oDomain = GetObject("WinNT://"&sDomainName) oDomain.Filter = Array("user") BEGIN COMMENT ' Examine each user account to determine whether the name in ' the argument matches the name associated with the account. END COMMENT For Each oUser In oDomain If LCase(oUser.Name) = LCase(sUserName) Then WScript.Echo oUser.Name & " already has an account." WScript.Quit End If Next End Sub # END CALLOUT A # BEGIN CALLOUT B Sub CreateUser Dim oUser, oDomain Set oDomain = GetObject("WinNT://"&sDomainName) BEGIN COMMENT ' Create the user object and associate it with a variable. END COMMENT Set oUser = oDomain.Create("user", sUserName) BEGIN COMMENT ' Set the new password. END COMMENT oUser.SetPassword "password" BEGIN COMMENT ' Write the new account information to the directory. END COMMENT oUser.SetInfo BEGIN COMMENT ' Enable the account. END COMMENT oUser.AccountDisabled = FALSE WScript.Echo "Account created for", sUserName, "in", _ sDomainName End Sub # END CALLOUT B ' Option Explicit Dim sUserName, sDomainName # BEGIN CALLOUT C BEGIN COMMENT ' Count the number of arguments. End the script if less than 2. END COMMENT If WScript.Arguments.Count < 2 Then WScript.Echo "Please provide a user name and " & _ "domain name in that order." WScript.Quit End If BEGIN COMMENT ' Assign the argument values to variables. END COMMENT sUserName = WScript.Arguments(0) sDomainName = WScript.Arguments(1) # END CALLOUT C BEGIN COMMENT ' Invoke the subroutines. END COMMENT Call QueryForUser Call CreateUser