Page 1 of 1 1
Topic Options
#191027 - 2008-12-11 04:01 AM Set Password Never Expires on local user account(s)
lukeod Offline
Getting the hang of it

Registered: 2008-01-11
Posts: 70
Loc: Australia
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)

Top
#191028 - 2008-12-11 04:16 AM Re: Set Password Never Expires on local user account(s) [Re: lukeod]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
See this thread:
http://www.kixtart.org/forums/ubbthreads...=true#Post36268

Top
#191030 - 2008-12-11 04:24 AM Re: Set Password Never Expires on local user account(s) [Re: Allen]
lukeod Offline
Getting the hang of it

Registered: 2008-01-11
Posts: 70
Loc: Australia
Hmm not sure how i didnt manage to find that with search \:\(

Ahh well, thanks muchly for the link, works great \:\)

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 581 anonymous users online.
Newest Members
Audio, Hoschi, Comet, rrosell, PatrickPinto
17880 Registered Users

Generated in 0.176 seconds in which 0.14 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org