Hey All,

Having *fun* with ADSI etc at the moment, as i am migrating our current shutdown script used for creating local accounts etc to Kix. Anyways, i've managed to figure out how to do most things with local accounts via COM, however i am unable to find any example code on how to set the password on a local user account to never expire.

From what i've read so far, it looks as though its possible to do via COM as well as WMI. I'm not fussed as to which one. I can determine if an account currently does not have the 'password never expires' flag using:

 Code:
 
$UserAccount = "SomeUserAccount"
$wmiColl = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_UserAccount WHERE LocalAccount = True")
	
	For Each $wmiObj in $wmiColl
		If $wmiObj.Name = $UserAccount
			If $wmiObj.PasswordExpires <> 0
				"password Currently Expires" 
			EndIf
		EndIf	
	Next


Also, i can display the current flags on an account by:

 Code:
$UserName = "SomeUserAccount"
$usr = GetObject("WinNT://" + @WKSTA + $UserName)
$oldFlags = $usr.Get("UserFlags")
"OldFlags = " + $oldFlags ?


However i cannot change these values \:\(

I've tried

 Code:
$usr.Put("UserFlags", "66049")
@SERROR
$usr.SetInfo
 


but get an error:


COM exception error "Put" ((null) - (null)) [-2147352567/80020009]



thanks in advance



Edited by lukeod (2008-12-11 04:06 AM)