wisem2540 Posted January 25, 2013 Posted January 25, 2013 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
water Posted January 25, 2013 Posted January 25, 2013 Domain user accounts? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
wisem2540 Posted January 25, 2013 Author Posted January 25, 2013 Sorry I didnt specify. These will be local accounts for windows 7, but XP compatibility would be helpful also.
water Posted January 25, 2013 Posted January 25, 2013 Can you post what you have so far to create local users? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
wisem2540 Posted January 25, 2013 Author Posted January 25, 2013 $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)
water Posted January 25, 2013 Posted January 25, 2013 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
wisem2540 Posted January 25, 2013 Author Posted January 25, 2013 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 = 0x10000Just for informational purposes.
water Posted January 25, 2013 Posted January 25, 2013 I combined the following scripts taken from MSDN Scripting Guys:Create a Local user AccountModify a Local User Account Password So It Never Expires Add Users to a Local Group My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
water Posted January 25, 2013 Posted January 25, 2013 I did some tests myself. The group name "Administrators" is language dependant. So the following script works for a german system: expandcollapse popup#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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now