Jump to content
Sign in to follow this  
wisem2540

Trying to create user accounts - how do I check the options for password?

Recommended Posts

wisem2540

So I have a scipt to create user accounts. But how do I make it tick the check boxes for "password never expires" and others?

thanks

Share this post


Link to post
Share on other sites
water

Domain user accounts?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
wisem2540

Sorry I didnt specify. These will be local accounts for windows 7, but XP compatibility would be helpful also.

Share this post


Link to post
Share on other sites
water

Can you post what you have so far to create local users?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
wisem2540
  • $username = InputBox( "Please Specify Username", "User Name: " )
        $password = InputBox( "Please Specify Password", "Password: " )
        Run(@ComSpec & " /c " & 'Net User ' & $username & " " & $password & " /add", "", @SW_HIDE)
        Run(@ComSpec & " /c " & "Net Localgroup Administrators " & $username & " /add", "", @SW_HIDE)

Share this post


Link to post
Share on other sites
water

This should create a user, assign a password, set it to never expire and add the user to the Administrators group.

Code is untested, so please be careful! Error handling is missing too!

Global $sUsername = InputBox( "Please Specify Username", "User Name: " )
Global $sPassword = InputBox( "Please Specify Password", "Password: " )
Global Const $ADS_UF_DONT_EXPIRE_PASSWD = 0x10000
; Create user
Global $oAccounts = ObjGet("WinNT://" & @ComputerName)
Global $oUser = $oAccounts.Create("user", $sUsername)
$oUser.SetPassword($sPassword)
$oUser.SetInfo
; Set password to not expire
$oUser.Put("userFlags", BitOr($oUser.Get("UserFlags"), $ADS_UF_DONT_EXPIRE_PASSWD))
$oUser.SetInfo
; assign to Administrator group
$sGroup = "Administrators"
Global $oGroup = ObjGet("WinNT://" & $sGroup & ",group")
$oGroup.Add($oUser.ADsPath)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
wisem2540

I tested it on a VM and it seems to work fine creating the account. There seems to be an issue in line 15 when it tries to add to the admin group. Would you be able to explain where you got the info for Global Const $ADS_UF_DONT_EXPIRE_PASSWD = 0x10000

Just for informational purposes.

Share this post


Link to post
Share on other sites
water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

I did some tests myself. The group name "Administrators" is language dependant. So the following script works for a german system:

#RequireAdmin
; Error monitoring. This will trap all COM errors while alive.
; This particular object is declared as local, meaning after the function returns it will not exist.
Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

Global $sUsername = InputBox("Please Specify Username", "User Name: ")
Global $sPassword = InputBox("Please Specify Password", "Password: ")
Global Const $ADS_UF_DONT_EXPIRE_PASSWD = 0x10000

; Create user
Global $oAccounts = ObjGet("WinNT://" & @ComputerName)
Global $oUser = $oAccounts.Create("user", $sUsername)
$oUser.SetPassword($sPassword)
MsgBox(0, "Setpassword", @error)
$oUser.SetInfo
MsgBox(0, "Setinfo Setpassword", @error)
; Set password to not expire
$oUser.Put("userFlags", BitOR($oUser.Get("UserFlags"), $ADS_UF_DONT_EXPIRE_PASSWD))
MsgBox(0, "Put", @error)
$oUser.SetInfo
MsgBox(0, "Setinfo Put", @error)
; assign to Administrator group
$sGroup = "Administratoren"
Global $oGroup = ObjGet("WinNT://" & @ComputerName & "/" & $sGroup & ",group")
MsgBox(0, "Objget", @error)
$oGroup.Add($oUser.ADsPath)
MsgBox(0, "Groupadd", @error)

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite("err.number is: " & @TAB & $oError.number & @CRLF & _
            "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            "err.description is: " & @TAB & $oError.description & @CRLF & _
            "err.source is: " & @TAB & $oError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            "err.retcode is: " & @TAB & $oError.retcode & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×