I want to use a script to modify a local account on a computer.

Now, the local account is configed, but the property of the local account is
that "user can't modify the password" and "Password never expires is
disabled". Now I want the property of the local account is that "user can
modify the password " and "Password never expires is now enabled".

Hope some one would help me !

Thanks a lot !

Re: Local Account by Richard

Richard
Wed Mar 15 23:45:52 CST 2006

Harry wrote:

>I want to use a script to modify a local account on a computer.
>
> Now, the local account is configed, but the property of the local account
> is that "user can't modify the password" and "Password never expires is
> disabled". Now I want the property of the local account is that "user can
> modify the password " and "Password never expires is now enabled".

Hi,

For local accounts you must use the WinNT provider. The relevant attribute
is userFlags and you must set the correct bits of this flag using bit masks.
For example:

' Define the bit mask constants.
Const ADS_UF_PASSWD_CANT_CHANGE = &H40
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000

' Bind to the user object with the WinNT provider.
Set objUser = GetObject("WinNT://MyDomain/TestUser,user")

' Retrieve userFlags attribute of user.
lngFlags = objUser.userFlags

' Set password never expires.
' The Or operator sets the bit for the corresponding flag.
lngFlags = lngFlags Or ADS_UF_DONT_EXPIRE_PASSWD

' Allow user to change the password.
' The only way to un-set the bit is to toggle the bit
' with the Xor operator if it is set.
' You test the bit with the And operator. If the
' And operation returns anything other than zero, the bit is set.
If (lngFlags And ADS_UF_PASSWD_CANT_CHANGE) <> 0 Then
' Account is configured so the password cannot be changed.
' Toggle the bit to allow the user to change the password.
lngFlags = lngFlags Xor ADS_UF_PASSWD_CANT_CHANGE
End If

' Assign the new value to the userFlags attribute of the user object.
objUser.userFlags = lngFlags

' Save the changes.
objUser.SetInfo

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net



Re: Local Account by Harry

Harry
Thu Mar 16 03:38:23 CST 2006

Perfect! Thanks a lot! Richard. I modified your script and run it on my
Virtual PC, I achieve my target. but the script is difficult to me, I only
understand a little. So, I think I need still learn it.

I have the other question, I am a chinese, I often go to the "Microsoft
Script Center" to learn the script, You know Microsoft only provide
Introduction of English version, I spended a lot of time to read and learn
it, Now, I only understand a part of it, And that introduction is very
simple.
I note you are mvp in script, would you like give me some suggestion about
learning script.

Thanks again.

"Richard Mueller" <rlmueller-NOSPAM@ameritech.NOSPAM.net> дÈëÏûÏ¢ÐÂÎÅ:eyt$kzLSGHA.256@TK2MSFTNGP14.phx.gbl...
> Harry wrote:
>
>>I want to use a script to modify a local account on a computer.
>>
>> Now, the local account is configed, but the property of the local account
>> is that "user can't modify the password" and "Password never expires is
>> disabled". Now I want the property of the local account is that "user can
>> modify the password " and "Password never expires is now enabled".
>
> Hi,
>
> For local accounts you must use the WinNT provider. The relevant attribute
> is userFlags and you must set the correct bits of this flag using bit
> masks. For example:
>
> ' Define the bit mask constants.
> Const ADS_UF_PASSWD_CANT_CHANGE = &H40
> Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
>
> ' Bind to the user object with the WinNT provider.
> Set objUser = GetObject("WinNT://MyDomain/TestUser,user")
>
> ' Retrieve userFlags attribute of user.
> lngFlags = objUser.userFlags
>
> ' Set password never expires.
> ' The Or operator sets the bit for the corresponding flag.
> lngFlags = lngFlags Or ADS_UF_DONT_EXPIRE_PASSWD
>
> ' Allow user to change the password.
> ' The only way to un-set the bit is to toggle the bit
> ' with the Xor operator if it is set.
> ' You test the bit with the And operator. If the
> ' And operation returns anything other than zero, the bit is set.
> If (lngFlags And ADS_UF_PASSWD_CANT_CHANGE) <> 0 Then
> ' Account is configured so the password cannot be changed.
> ' Toggle the bit to allow the user to change the password.
> lngFlags = lngFlags Xor ADS_UF_PASSWD_CANT_CHANGE
> End If
>
> ' Assign the new value to the userFlags attribute of the user object.
> objUser.userFlags = lngFlags
>
> ' Save the changes.
> objUser.SetInfo
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
>



Re: Local Account by Richard

Richard
Thu Mar 16 11:52:38 CST 2006

Harry,

The best reference is "Microsoft Windows 2000 Scripting Guide - Automating
System Administration". It covers VBScript, WSH, ADSI, ADO, and WMI. This
text is available online at:

http://www.microsoft.com/resources/documentation/windows/2000/server/scriptguide/en-us/sagsas_overview.mspx

The text uses the LDAP provider, but the principles are the same. A
discussion of user flags (the userAccountControl attribute exposed by LDAP
is the same as the userFlags attribute exposed by WinNT) is here:

http://www.microsoft.com/technet/scriptcenter/guide/sas_usr_hhdp.mspx

If you can find it, I would also recommend:

"Windows NT/2000 - ADSI Scripting for System Administration", by Thomas Eck.
Macmillan Publishing USA

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

"Harry" <berciwang@hotmail.com> wrote in message
news:%23Ktzg1NSGHA.4300@TK2MSFTNGP14.phx.gbl...
> Perfect! Thanks a lot! Richard. I modified your script and run it on my
> Virtual PC, I achieve my target. but the script is difficult to me, I only
> understand a little. So, I think I need still learn it.
>
> I have the other question, I am a chinese, I often go to the "Microsoft
> Script Center" to learn the script, You know Microsoft only provide
> Introduction of English version, I spended a lot of time to read and learn
> it, Now, I only understand a part of it, And that introduction is very
> simple.
> I note you are mvp in script, would you like give me some suggestion about
> learning script.
>
> Thanks again.
>
> "Richard Mueller" <rlmueller-NOSPAM@ameritech.NOSPAM.net>
> дÈëÏûÏ¢ÐÂÎÅ:eyt$kzLSGHA.256@TK2MSFTNGP14.phx.gbl...
>> Harry wrote:
>>
>>>I want to use a script to modify a local account on a computer.
>>>
>>> Now, the local account is configed, but the property of the local
>>> account is that "user can't modify the password" and "Password never
>>> expires is disabled". Now I want the property of the local account is
>>> that "user can modify the password " and "Password never expires is now
>>> enabled".
>>
>> Hi,
>>
>> For local accounts you must use the WinNT provider. The relevant
>> attribute is userFlags and you must set the correct bits of this flag
>> using bit masks. For example:
>>
>> ' Define the bit mask constants.
>> Const ADS_UF_PASSWD_CANT_CHANGE = &H40
>> Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
>>
>> ' Bind to the user object with the WinNT provider.
>> Set objUser = GetObject("WinNT://MyDomain/TestUser,user")
>>
>> ' Retrieve userFlags attribute of user.
>> lngFlags = objUser.userFlags
>>
>> ' Set password never expires.
>> ' The Or operator sets the bit for the corresponding flag.
>> lngFlags = lngFlags Or ADS_UF_DONT_EXPIRE_PASSWD
>>
>> ' Allow user to change the password.
>> ' The only way to un-set the bit is to toggle the bit
>> ' with the Xor operator if it is set.
>> ' You test the bit with the And operator. If the
>> ' And operation returns anything other than zero, the bit is set.
>> If (lngFlags And ADS_UF_PASSWD_CANT_CHANGE) <> 0 Then
>> ' Account is configured so the password cannot be changed.
>> ' Toggle the bit to allow the user to change the password.
>> lngFlags = lngFlags Xor ADS_UF_PASSWD_CANT_CHANGE
>> End If
>>
>> ' Assign the new value to the userFlags attribute of the user object.
>> objUser.userFlags = lngFlags
>>
>> ' Save the changes.
>> objUser.SetInfo
>>
>> --
>> Richard
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>>
>
>



Re: Local Account by Harry

Harry
Fri Mar 17 03:24:56 CST 2006

Thanks a lot! Richard! Well, I think I will spend some time to learn the
windows script.

thanks again.
"Richard Mueller" <rlmueller-NOSPAM@ameritech.NOSPAM.net> дÈëÏûÏ¢ÐÂÎÅ:%23Dn6sJSSGHA.336@TK2MSFTNGP12.phx.gbl...
> Harry,
>
> The best reference is "Microsoft Windows 2000 Scripting Guide - Automating
> System Administration". It covers VBScript, WSH, ADSI, ADO, and WMI. This
> text is available online at:
>
> http://www.microsoft.com/resources/documentation/windows/2000/server/scriptguide/en-us/sagsas_overview.mspx
>
> The text uses the LDAP provider, but the principles are the same. A
> discussion of user flags (the userAccountControl attribute exposed by LDAP
> is the same as the userFlags attribute exposed by WinNT) is here:
>
> http://www.microsoft.com/technet/scriptcenter/guide/sas_usr_hhdp.mspx
>
> If you can find it, I would also recommend:
>
> "Windows NT/2000 - ADSI Scripting for System Administration", by Thomas
> Eck. Macmillan Publishing USA
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
>
> "Harry" <berciwang@hotmail.com> wrote in message
> news:%23Ktzg1NSGHA.4300@TK2MSFTNGP14.phx.gbl...
>> Perfect! Thanks a lot! Richard. I modified your script and run it on my
>> Virtual PC, I achieve my target. but the script is difficult to me, I
>> only understand a little. So, I think I need still learn it.
>>
>> I have the other question, I am a chinese, I often go to the "Microsoft
>> Script Center" to learn the script, You know Microsoft only provide
>> Introduction of English version, I spended a lot of time to read and
>> learn it, Now, I only understand a part of it, And that introduction is
>> very simple.
>> I note you are mvp in script, would you like give me some suggestion
>> about learning script.
>>
>> Thanks again.
>>
>> "Richard Mueller" <rlmueller-NOSPAM@ameritech.NOSPAM.net> дÈëÏûÏ¢ÐÂÎÅ:eyt$kzLSGHA.256@TK2MSFTNGP14.phx.gbl...
>>> Harry wrote:
>>>
>>>>I want to use a script to modify a local account on a computer.
>>>>
>>>> Now, the local account is configed, but the property of the local
>>>> account is that "user can't modify the password" and "Password never
>>>> expires is disabled". Now I want the property of the local account is
>>>> that "user can modify the password " and "Password never expires is now
>>>> enabled".
>>>
>>> Hi,
>>>
>>> For local accounts you must use the WinNT provider. The relevant
>>> attribute is userFlags and you must set the correct bits of this flag
>>> using bit masks. For example:
>>>
>>> ' Define the bit mask constants.
>>> Const ADS_UF_PASSWD_CANT_CHANGE = &H40
>>> Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
>>>
>>> ' Bind to the user object with the WinNT provider.
>>> Set objUser = GetObject("WinNT://MyDomain/TestUser,user")
>>>
>>> ' Retrieve userFlags attribute of user.
>>> lngFlags = objUser.userFlags
>>>
>>> ' Set password never expires.
>>> ' The Or operator sets the bit for the corresponding flag.
>>> lngFlags = lngFlags Or ADS_UF_DONT_EXPIRE_PASSWD
>>>
>>> ' Allow user to change the password.
>>> ' The only way to un-set the bit is to toggle the bit
>>> ' with the Xor operator if it is set.
>>> ' You test the bit with the And operator. If the
>>> ' And operation returns anything other than zero, the bit is set.
>>> If (lngFlags And ADS_UF_PASSWD_CANT_CHANGE) <> 0 Then
>>> ' Account is configured so the password cannot be changed.
>>> ' Toggle the bit to allow the user to change the password.
>>> lngFlags = lngFlags Xor ADS_UF_PASSWD_CANT_CHANGE
>>> End If
>>>
>>> ' Assign the new value to the userFlags attribute of the user object.
>>> objUser.userFlags = lngFlags
>>>
>>> ' Save the changes.
>>> objUser.SetInfo
>>>
>>> --
>>> Richard
>>> Microsoft MVP Scripting and ADSI
>>> Hilltop Lab - http://www.rlmueller.net
>>>
>>
>>
>
>