Question

Locked

VBScripting - Creating Multiple Local Users

By eddieduce ·
How can I be sure that there are always three digits as part of the Username number, i.e. 'User-001', 010, 100 and not 'User-1' or '10'?


I'm also testing so that the script tells me how many accounts it created based out of the 'i' value but all I get is the stopping value, which is always one number more than what it's actually created.

Thanks in advanced.

Here is my script:

'::========================================================================
'::ERROR CODES
'::========================================================================
'::800A01A8 OBJECT REQUIRE ' ' Microsoft VBScript runtime error
'::80070057 One or more arguments are invalid Active Directory
'::8007007B The filename, directory name,or volumelabel syntax is incorrect. (null)
'::========================================================================
Option Explicit
Dim strComputer, objComputer, strName, objUser
Dim strFullName, lngFlag, strPassword
Dim strNumberOfAccounts
DIM i
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
' Specify local computer.
' This could also be retrieved from the wshNetwork object programmatically.
strComputer = "."
i=0
' Bind to the local computer object.
Set objComputer = GetObject("WinNT://" & strComputer)
' Specify local user name.
' Start 'FOR' loop.
strNumberOfAccounts = InputBox("Enter number of accounts to create")
for i = 1 to strNumberOfAccounts
strName = "ACCOUNT-"
' Create local user object.
Set objUser = objComputer.Create("User", strName & i) ' removing the 'i' will createthe account with an error message.
' Assign properties, like Full Name.
strFullName = "Sample Account"
objUser.Put "FullName", strFullName
' Save the user object.
objUser.SetInfo
' Set password
strPassword = "USERPASSWORD"
objUser.SetPassword strPassword
' Set user flag so password never expires.
lngFlag = objUser.Get("UserFlags")
lngFlag = lngFlag Or ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put "UserFlags", lngFlag
' Save change.
objUser.SetInfo
NEXT
WScript.echo " '" & strName & "' " & i & "account was created successfully!"
'::========================================================================

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

test for i

by LarryD4 In reply to VBScripting - Creating Mu ...

Test i each time you create an account before you define the name of the account


if i >= 1 and < 10 Then
strName = "ACCOUNT-00" & i
Elseif i >= 10 and < 100 Then
strName = "ACCOUNT-0" & i
Elseif i >= 100 and < 1000 Then
strName = "ACCOUNT-" & i

Collapse -

...Script is Progressing

by eddieduce In reply to test for i

Larry, thanks. This is what I did:
--------------------------
IF i <10 then
i = Right("00" & i, 3)
ELSE
END IF
IF i >=10 & i <100 THEN
i = Right("0" & i, 3)
ELSE
END IF
-----------------------

I am trying to set the 'User cannot change password' flag but for some reason it is not going through. This is what I tried:
--------------------------
DIM ADS_PASSWORD_CANT_CHANGE
Const ADS_UF_PASSWD_CANT_CHANGE = &H0040
':: Set User Cannot Change Password.
objUser.ADS_PASSWORD_CANT_CHANGE = True
':: Save the user object.
objUser.SetInfo
-------------------------

Collapse -

Umm

by LarryD4 In reply to ...Script is Progressing

If I'm reading this right your making ADS_UF_PASSWD_CANT_CHANGE a constant with a value of &H0040

Then your trying to change the value of that contant to something else.

Try it with out the Constant declaration.

Collapse -

No Difference

by eddieduce In reply to Umm

There was no difference. I have seen in other posted scripts that they use one of these two entries:

ADS_UF_PASSWD_CANT_CHANGE

or

ADS_UF_PASSWORD_CANT_CHANGE

Which should be the correct one? How do I find all other fields I can set?

Thanks,

-ED

Related Discussions

Related Forums