Jump to content

Creating a local admin and setting password to never expire


CiS
 Share

Recommended Posts

Hello all! Thanks so far for the help. I have been reading a searching this message board all day. I have 0 experience with scripting. I am trying to create a simple script to add a user, put them in the admin group, set a password, and make the password never expire.

This example has worked great for me but I cannot figure out what I need to do to set the password to never expire on just this account. Can someone please help?

I'm thinking is has something to do with this but I can't figure out where to add it or to get it working correctly

Const $ADS_UF_DONT_EXPIRE_PASSWD = 0x10000

$objUserFlags = $objUser.Get("UserFlags")

$objPasswordExpirationFlag = BitOR($objUserFlags,$ADS_UF_DONT_EXPIRE_PASSWD)

$objUser.Put ("UserFlags", $objPasswordExpirationFlag)

$objUser.SetInfo

Any help would be greatly appreciated!

Here's a COM version to add a user and add it to Administrators:

; Init objects
$UserName = 'Fred'
$Password = 'Wilma'
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler 
$strComputer = @ComputerName
$colAccounts = ObjGet("WinNT://" & $strComputer & "")
$objUser = $colAccounts.Create("user", $UserName)
$objUser.SetPassword ($Password)
$objUser.Put ("Fullname", "Test User")
$objUser.Put ("Description", "Test User description")
$objUser.SetInfo
;Add User to group 
$objGroup = ObjGet("WinNT://" & $strComputer & "/Administrators,group")
$objGroup.Add($objUser.ADsPath)
;
;
; This is my custom error handler 
Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
;~  Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
;~               "Number is: " & $HexNumber & @CRLF & _
;~               "Linenbr is: " & $oMyError.scriptline  & @CRLF & _
;~               "Description is: " & $oMyError.description  & @CRLF & _
;~               "Windescription is: " & $oMyError.windescription ) 

   SetError(1); something to check for when this function returns 
Endfunc
Edited by CiS
Link to comment
Share on other sites

Question sounds familiar...

There was this rakishly good looking flightless water fowl who posted a function called _UserCtrlAttribs(). That might work for you.

;)

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Sorry,just figured I wouldn't get much of a reply since the thread was so old...

I did see your response. Like I said in the post I really have no knowledge of scripting. Do I need all of that just to be able to set the password not to expire? That is the only thing that I cannot get working.

Link to comment
Share on other sites

Sorry,just figured I wouldn't get much of a reply since the thread was so old...

I did see your response. Like I said in the post I really have no knowledge of scripting. Do I need all of that just to be able to set the password not to expire? That is the only thing that I cannot get working.

_UserCtrlAttribs is a generalized function that can be used control many attributes and thoroughly reports any errors. If you really want the bare minimum:

$sUsrName = "Fred.Flinstone"
Local $objUser = ObjGet("WinNT://./" & $sUsrName & ", User")
$objUser.Put ("UserFlags", BitOR($objUser.get ("UserFlags"), 0x10000))
$objUser.SetInfo

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...