Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - clear the ‘password never expires’

Reply
 
Old 10-08-2008   #1 (permalink)
pinecone


 
 

clear the ‘password never expires’

Stand-alone XP machine. How can I script to clear the 'password never
expires' check box?
TIA,
Bob

My System SpecsSystem Spec
Old 10-08-2008   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: clear the ‘password never expires’

Bob wrote:
Quote:

> Stand-alone XP machine. How can I script to clear the 'password never
> expires' check box?
For one local user:
========
' Bit mask for password never espires.
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000

' Bind to user object.
Set objUser = GetObject("WinNT://MyComputer/JSmith,user")
' Retrieve flags attribute
lngFlags = objUser.userFlags
' Set bit.
lngFlags = lngFlags Or ADS_UF_DONT_EXPIRE_PASSWD
' Save changes.
objUser.userFlags = lngFlags
objUser.SetInfo
=======
For all local users in the local SAM account database (assuming you have
permissions):
========
' Bit mask for password never espires.
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000

' Bind to the computer object.
Set objComputer = GetObject("WinNT://MyComputer")
' Filter on user objects.
objComputer.Filter = Array("user")
' Enumerate all users.
For Each objUser In objComputer
' Retrieve flags attribute
lngFlags = objUser.userFlags
' Set bit.
lngFlags = lngFlags Or ADS_UF_DONT_EXPIRE_PASSWD
' Save changes.
objUser.userFlags = lngFlags
objUser.SetInfo
Next

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 10-08-2008   #3 (permalink)
pinecone


 
 

Re: clear the ‘password never expires’



"Richard Mueller [MVP]" wrote:
Quote:

> Bob wrote:
>
Quote:

> > Stand-alone XP machine. How can I script to clear the 'password never
> > expires' check box?
>
> For one local user:
> ========
> ' Bit mask for password never espires.
> Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
>
> ' Bind to user object.
> Set objUser = GetObject("WinNT://MyComputer/JSmith,user")
> ' Retrieve flags attribute
> lngFlags = objUser.userFlags
> ' Set bit.
> lngFlags = lngFlags Or ADS_UF_DONT_EXPIRE_PASSWD
> ' Save changes.
> objUser.userFlags = lngFlags
> objUser.SetInfo
> =======
> For all local users in the local SAM account database (assuming you have
> permissions):
> ========
> ' Bit mask for password never espires.
> Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
>
> ' Bind to the computer object.
> Set objComputer = GetObject("WinNT://MyComputer")
> ' Filter on user objects.
> objComputer.Filter = Array("user")
> ' Enumerate all users.
> For Each objUser In objComputer
> ' Retrieve flags attribute
> lngFlags = objUser.userFlags
> ' Set bit.
> lngFlags = lngFlags Or ADS_UF_DONT_EXPIRE_PASSWD
> ' Save changes.
> objUser.userFlags = lngFlags
> objUser.SetInfo
> Next
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
> Thanks Rich,
Your script set the bit, I need to reset (clear the chechbox). I XORd the
flags and that seems to reset the bit. Now I can set the 'change password on
next logon'.
Bob
Quote:

>
My System SpecsSystem Spec
Old 10-08-2008   #4 (permalink)
Richard Mueller [MVP]


 
 

Re: clear the ‘password never expires’


"pinecone" <pinecone@xxxxxx> wrote in message
news:9C62635B-0DDE-4721-AAD1-49D7BF6D8E33@xxxxxx
Quote:

>
>
> "Richard Mueller [MVP]" wrote:
>
Quote:

>> Bob wrote:
>>
Quote:

>> > Stand-alone XP machine. How can I script to clear the 'password never
>> > expires' check box?
>>
>> For one local user:
>> ========
>> ' Bit mask for password never espires.
>> Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
>>
>> ' Bind to user object.
>> Set objUser = GetObject("WinNT://MyComputer/JSmith,user")
>> ' Retrieve flags attribute
>> lngFlags = objUser.userFlags
>> ' Set bit.
>> lngFlags = lngFlags Or ADS_UF_DONT_EXPIRE_PASSWD
>> ' Save changes.
>> objUser.userFlags = lngFlags
>> objUser.SetInfo
>> =======
>> For all local users in the local SAM account database (assuming you have
>> permissions):
>> ========
>> ' Bit mask for password never espires.
>> Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
>>
>> ' Bind to the computer object.
>> Set objComputer = GetObject("WinNT://MyComputer")
>> ' Filter on user objects.
>> objComputer.Filter = Array("user")
>> ' Enumerate all users.
>> For Each objUser In objComputer
>> ' Retrieve flags attribute
>> lngFlags = objUser.userFlags
>> ' Set bit.
>> lngFlags = lngFlags Or ADS_UF_DONT_EXPIRE_PASSWD
>> ' Save changes.
>> objUser.userFlags = lngFlags
>> objUser.SetInfo
>> Next
>>
>> --
>> Richard Mueller
>> MVP Directory Services
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>> Thanks Rich,
> Your script set the bit, I need to reset (clear the chechbox). I XORd the
> flags and that seems to reset the bit. Now I can set the 'change password
> on
> next logon'.
> Bob
Quote:

>>
Sorry, I didn't read carefully. Just to make it clear, the Xor operator
toggles the bit. If the bit is set, Xor unsets it. If the bit is not set,
Xor sets it. You need to test the bit first, using the And operator (any
non-zero result means the bit is set), then Xor only if the bit is set. The
code would be similar (for one user):
==========
' Bit mask for password never espires.
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000

' Bind to user object.
Set objUser = GetObject("WinNT://MyComputer/JSmith,user")
' Retrieve flags attribute
lngFlags = objUser.userFlags
' Test the bit.
If (lngFlags And ADS_UF_DONT_EXPIRE_PASSWD) <> 0 Then
' The bit is set. Toggle the bit.
lngFlags = lngFlags Xor ADS_UF_DONT_EXPIRE_PASSWD
' Save changes.
objUser.userFlags = lngFlags
objUser.SetInfo
End If

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 10-08-2008   #5 (permalink)
\RemS


 
 

Re: clear the ‘password never expires’

"pinecone" wrote:
Quote:

>
>
> "Richard Mueller [MVP]" wrote:
>
Quote:

> > Bob wrote:
> >
Quote:

> > > Stand-alone XP machine. How can I script to clear the 'password never
> > > expires' check box?
> >
> > For one local user:
> > ========
> > ' Bit mask for password never espires.
> > Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
> >
> > ' Bind to user object.
> > Set objUser = GetObject("WinNT://MyComputer/JSmith,user")
> > ' Retrieve flags attribute
> > lngFlags = objUser.userFlags
> > ' Set bit.
> > lngFlags = lngFlags Or ADS_UF_DONT_EXPIRE_PASSWD
> > ' Save changes.
> > objUser.userFlags = lngFlags
> > objUser.SetInfo
> > =======
> > For all local users in the local SAM account database (assuming you have
> > permissions):
> > ========
> > ' Bit mask for password never espires.
> > Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
> >
> > ' Bind to the computer object.
> > Set objComputer = GetObject("WinNT://MyComputer")
> > ' Filter on user objects.
> > objComputer.Filter = Array("user")
> > ' Enumerate all users.
> > For Each objUser In objComputer
> > ' Retrieve flags attribute
> > lngFlags = objUser.userFlags
> > ' Set bit.
> > lngFlags = lngFlags Or ADS_UF_DONT_EXPIRE_PASSWD
> > ' Save changes.
> > objUser.userFlags = lngFlags
> > objUser.SetInfo
> > Next
> >
> > --
> > Richard Mueller
> > MVP Directory Services
> > Hilltop Lab - http://www.rlmueller.net
> > --
> >
> > Thanks Rich,
> Your script set the bit, I need to reset (clear the chechbox). I XORd the
> flags and that seems to reset the bit. Now I can set the 'change password on
> next logon'.
> Bob
Quote:

> >
To set the 'change password on next logon',

''''''
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
Const ADS_UF_PASSWORD_EXPIRED = &H800000

sUserName = "name.."

' get computer name
Set oWshNet = CreateObject("WScript.Network" )
sComputerName = oWshNet.ComputerName

Set oUser = GetObject("WinNT://" _
& sComputerName & "/" & sUserName & ", user")

lngFlags = oUser.Get("UserFlags")

If lngFlags AND ADS_UF_DONT_EXPIRE_PASSWD Then
oUser.Put "UserFlags", lngFlags XOR ADS_UF_DONT_EXPIRE_PASSWD
oUser.SetInfo
End If

If Not lngFlags AND ADS_UF_PASSWORD_EXPIRED Then
oUser.Put "PasswordExpired", 1
oUser.SetInfo
End If
''''''

\Rems
My System SpecsSystem Spec
Old 10-08-2008   #6 (permalink)
Al Dunbar


 
 

Re: clear the 'password never expires'


"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
message news:ukAa%238VKJHA.4708@xxxxxx
Quote:

>
> "pinecone" <pinecone@xxxxxx> wrote in message
> news:9C62635B-0DDE-4721-AAD1-49D7BF6D8E33@xxxxxx
Quote:

>>
>>
>> "Richard Mueller [MVP]" wrote:
>>
Quote:

>>> Bob wrote:
>>>
>>> > Stand-alone XP machine. How can I script to clear the 'password never
>>> > expires' check box?
>>>
>>> For one local user:
>>> ========
>>> ' Bit mask for password never espires.
>>> Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
>>>
>>> ' Bind to user object.
>>> Set objUser = GetObject("WinNT://MyComputer/JSmith,user")
>>> ' Retrieve flags attribute
>>> lngFlags = objUser.userFlags
>>> ' Set bit.
>>> lngFlags = lngFlags Or ADS_UF_DONT_EXPIRE_PASSWD
>>> ' Save changes.
>>> objUser.userFlags = lngFlags
>>> objUser.SetInfo
>>> =======
>>> For all local users in the local SAM account database (assuming you have
>>> permissions):
>>> ========
>>> ' Bit mask for password never espires.
>>> Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
>>>
>>> ' Bind to the computer object.
>>> Set objComputer = GetObject("WinNT://MyComputer")
>>> ' Filter on user objects.
>>> objComputer.Filter = Array("user")
>>> ' Enumerate all users.
>>> For Each objUser In objComputer
>>> ' Retrieve flags attribute
>>> lngFlags = objUser.userFlags
>>> ' Set bit.
>>> lngFlags = lngFlags Or ADS_UF_DONT_EXPIRE_PASSWD
>>> ' Save changes.
>>> objUser.userFlags = lngFlags
>>> objUser.SetInfo
>>> Next
>>>
>>> --
>>> Richard Mueller
>>> MVP Directory Services
>>> Hilltop Lab - http://www.rlmueller.net
>>> --
>>>
>>> Thanks Rich,
>> Your script set the bit, I need to reset (clear the chechbox). I XORd the
>> flags and that seems to reset the bit. Now I can set the 'change password
>> on
>> next logon'.
>> Bob
Quote:

>>>
>
> Sorry, I didn't read carefully. Just to make it clear, the Xor operator
> toggles the bit. If the bit is set, Xor unsets it. If the bit is not set,
> Xor sets it. You need to test the bit first, using the And operator
That certainly works. But there is a simple way to clear a bit
unconditionally without testing it first to see if it needs to be XOR'd:

bitmask = &H10000
value1 = &H30000 ' the bit is set
value2 = &H40000 ' the bit is clear
clear1 = value1 and not bitmask
clear2 = value2 and not bitmask
wscript.echo value1 & ":" & clear1 & "<= should differ"
wscript.echo value2 & ":" & clear2 & "<= should be the same"

In the script given, this could be done as simply as:

' Bind to user object.
Set objUser = GetObject("WinNT://MyComputer/JSmith,user")
' set (possibly) new value.
objUser.userFlags = objUser.userFlags and not ADS_UF_DONT_EXPIRE_PASSWD
objUser.SetInfo

You might still want to make the .SetInfo conditional on the new value being
different, but this is still (slightly) simpler (imho), although it requires
either an additional variable or referencing the .userFlags attribute more
than once.

' Bind to user object.
Set objUser = GetObject("WinNT://MyComputer/JSmith,user")
' Retrieve flags attribute
lngFlags = objUser.userFlags
lnFlags2 = lngFlags and not ADS_UF_DONT_EXPIRE_PASSWD
' if the value changed, update AD
If (lngFlags <> lngFlags2) Then
' Save changes.
objUser.userFlags = lngFlags2
objUser.SetInfo
End If

Just booling around here, but this reminds me of a question you are unlikely
to hear on Jeopardy:

A: "FF is the answer you nincompoop!" - hexadecimally inclined critic of
famed Elizabethan playwright.
Q: what is "2B or not 2B", Alex?

I'll leave the arithmetic of this one as an exercise for the reader.


/Al
Quote:

> (any non-zero result means the bit is set), then Xor only if the bit is
> set. The code would be similar (for one user):
> ==========
> ' Bit mask for password never espires.
> Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
>
> ' Bind to user object.
> Set objUser = GetObject("WinNT://MyComputer/JSmith,user")
> ' Retrieve flags attribute
> lngFlags = objUser.userFlags
> ' Test the bit.
> If (lngFlags And ADS_UF_DONT_EXPIRE_PASSWD) <> 0 Then
> ' The bit is set. Toggle the bit.
> lngFlags = lngFlags Xor ADS_UF_DONT_EXPIRE_PASSWD
> ' Save changes.
> objUser.userFlags = lngFlags
> objUser.SetInfo
> End If
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>

My System SpecsSystem Spec
Old 10-09-2008   #7 (permalink)
pinecone


 
 

Re: clear the 'password never expires'

Thanks for your help!
Bob


"Al Dunbar" wrote:
Quote:

>
> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
> message news:ukAa%238VKJHA.4708@xxxxxx
Quote:

> >
> > "pinecone" <pinecone@xxxxxx> wrote in message
> > news:9C62635B-0DDE-4721-AAD1-49D7BF6D8E33@xxxxxx
Quote:

> >>
> >>
> >> "Richard Mueller [MVP]" wrote:
> >>
> >>> Bob wrote:
> >>>
> >>> > Stand-alone XP machine. How can I script to clear the 'password never
> >>> > expires' check box?
> >>>
> >>> For one local user:
> >>> ========
> >>> ' Bit mask for password never espires.
> >>> Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
> >>>
> >>> ' Bind to user object.
> >>> Set objUser = GetObject("WinNT://MyComputer/JSmith,user")
> >>> ' Retrieve flags attribute
> >>> lngFlags = objUser.userFlags
> >>> ' Set bit.
> >>> lngFlags = lngFlags Or ADS_UF_DONT_EXPIRE_PASSWD
> >>> ' Save changes.
> >>> objUser.userFlags = lngFlags
> >>> objUser.SetInfo
> >>> =======
> >>> For all local users in the local SAM account database (assuming you have
> >>> permissions):
> >>> ========
> >>> ' Bit mask for password never espires.
> >>> Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
> >>>
> >>> ' Bind to the computer object.
> >>> Set objComputer = GetObject("WinNT://MyComputer")
> >>> ' Filter on user objects.
> >>> objComputer.Filter = Array("user")
> >>> ' Enumerate all users.
> >>> For Each objUser In objComputer
> >>> ' Retrieve flags attribute
> >>> lngFlags = objUser.userFlags
> >>> ' Set bit.
> >>> lngFlags = lngFlags Or ADS_UF_DONT_EXPIRE_PASSWD
> >>> ' Save changes.
> >>> objUser.userFlags = lngFlags
> >>> objUser.SetInfo
> >>> Next
> >>>
> >>> --
> >>> Richard Mueller
> >>> MVP Directory Services
> >>> Hilltop Lab - http://www.rlmueller.net
> >>> --
> >>>
> >>> Thanks Rich,
> >> Your script set the bit, I need to reset (clear the chechbox). I XORd the
> >> flags and that seems to reset the bit. Now I can set the 'change password
> >> on
> >> next logon'.
> >> Bob
> >>>
> >
> > Sorry, I didn't read carefully. Just to make it clear, the Xor operator
> > toggles the bit. If the bit is set, Xor unsets it. If the bit is not set,
> > Xor sets it. You need to test the bit first, using the And operator
>
> That certainly works. But there is a simple way to clear a bit
> unconditionally without testing it first to see if it needs to be XOR'd:
>
> bitmask = &H10000
> value1 = &H30000 ' the bit is set
> value2 = &H40000 ' the bit is clear
> clear1 = value1 and not bitmask
> clear2 = value2 and not bitmask
> wscript.echo value1 & ":" & clear1 & "<= should differ"
> wscript.echo value2 & ":" & clear2 & "<= should be the same"
>
> In the script given, this could be done as simply as:
>
> ' Bind to user object.
> Set objUser = GetObject("WinNT://MyComputer/JSmith,user")
> ' set (possibly) new value.
> objUser.userFlags = objUser.userFlags and not ADS_UF_DONT_EXPIRE_PASSWD
> objUser.SetInfo
>
> You might still want to make the .SetInfo conditional on the new value being
> different, but this is still (slightly) simpler (imho), although it requires
> either an additional variable or referencing the .userFlags attribute more
> than once.
>
> ' Bind to user object.
> Set objUser = GetObject("WinNT://MyComputer/JSmith,user")
> ' Retrieve flags attribute
> lngFlags = objUser.userFlags
> lnFlags2 = lngFlags and not ADS_UF_DONT_EXPIRE_PASSWD
> ' if the value changed, update AD
> If (lngFlags <> lngFlags2) Then
> ' Save changes.
> objUser.userFlags = lngFlags2
> objUser.SetInfo
> End If
>
> Just booling around here, but this reminds me of a question you are unlikely
> to hear on Jeopardy:
>
> A: "FF is the answer you nincompoop!" - hexadecimally inclined critic of
> famed Elizabethan playwright.
> Q: what is "2B or not 2B", Alex?
>
> I'll leave the arithmetic of this one as an exercise for the reader.
>
>
> /Al
>
Quote:

> > (any non-zero result means the bit is set), then Xor only if the bit is
> > set. The code would be similar (for one user):
> > ==========
> > ' Bit mask for password never espires.
> > Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
> >
> > ' Bind to user object.
> > Set objUser = GetObject("WinNT://MyComputer/JSmith,user")
> > ' Retrieve flags attribute
> > lngFlags = objUser.userFlags
> > ' Test the bit.
> > If (lngFlags And ADS_UF_DONT_EXPIRE_PASSWD) <> 0 Then
> > ' The bit is set. Toggle the bit.
> > lngFlags = lngFlags Xor ADS_UF_DONT_EXPIRE_PASSWD
> > ' Save changes.
> > objUser.userFlags = lngFlags
> > objUser.SetInfo
> > End If
> >
> > --
> > Richard Mueller
> > MVP Directory Services
> > Hilltop Lab - http://www.rlmueller.net
> > --
> >
> >
>
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
dataset does not clear .NET General
To clear the air Vista General
How do I clear this? Vista General
256MB (NOT 512). sorry if I wasn't clear Vista General
Clear DNS problem Vista networking & sharing


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46