Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 



dslider

Password Never Expires - Changing automatically

Recommended Posts

dslider    0

From the command line is there a way to uncheck the "Password Never Expires" setting? I am doing this for the LOCAL machine only. I am trying to do this from a bat file that I will be running on computer after it has been syspreped. Any one know they command to do this?

Edited by dslider

Share this post


Link to post
Share on other sites

neo    1
From the command line is there a way to uncheck the "Password Never Expires" setting? I am doing this for the LOCAL machine only. I am trying to do this from a bat file that I will be running on computer after it has been syspreped. Any one know they command to do this?

:thumbup try this:

net accounts /maxpwage:unlimited

Share this post


Link to post
Share on other sites
dslider    0

maybe I was a little vague on my issue..... I need the "Password Never Expires" box to be unchecked.....meaning that the password will expire according to my Group Policy setting.... is there a way to achieve this from the command line?

Edited by dslider

Share this post


Link to post
Share on other sites

Here is a batch file that uses a vbscript to perform the task:

Save this as pwexpire.cmd

@echo off
if not [%1]==[] (
echo Const ADS_UF_DONT_EXPIRE_PASSWD = ^&H10000 >.\pwexpire.vbs
echo Dim User >>.\pwexpire.vbs
echo Dim usrflags >>.\pwexpire.vbs
echo Set User = GetObject^("WinNT://./%1,user"^) >>.\pwexpire.vbs
echo usrflags= User.Get^("UserFlags"^) >>.\pwexpire.vbs
echo User.Put "userFlags", usrflags Or ADS_UF_DONT_EXPIRE_PASSWD >>.\pwexpire.vbs
echo User.SetInfo >>.\pwexpire.vbs
echo Set User = Nothing >>.\pwexpire.vbs

cscript //nologo .\pwexpire.vbs
if exist .\pwexpire.vbs del .\pwexpire.vbs
)

Call this batch file like this:

pwexpire.cmd userid

Share this post


Link to post
Share on other sites
dslider    0
Here is a batch file that uses a vbscript to perform the task:

Save this as pwexpire.cmd

@echo off
if not [%1]==[] (
echo Const ADS_UF_DONT_EXPIRE_PASSWD = ^&H10000 >.\pwexpire.vbs
echo Dim User >>.\pwexpire.vbs
echo Dim usrflags >>.\pwexpire.vbs
echo Set User = GetObject^("WinNT://./%1,user"^) >>.\pwexpire.vbs
echo usrflags= User.Get^("UserFlags"^) >>.\pwexpire.vbs
echo User.Put "userFlags", usrflags Or ADS_UF_DONT_EXPIRE_PASSWD >>.\pwexpire.vbs
echo User.SetInfo >>.\pwexpire.vbs
echo Set User = Nothing >>.\pwexpire.vbs

cscript //nologo .\pwexpire.vbs
if exist .\pwexpire.vbs del .\pwexpire.vbs
)

Call this batch file like this:

pwexpire.cmd userid

This does not uncheck the "Password never Expires" box... but it will check it for you.. how can I make it uncheck the box?

Share this post


Link to post
Share on other sites

Oops! Sorry about that. Here is a correction:

@echo off
if not [%1]==[] (
echo Const ADS_UF_EXPIRE_PASSWD = ^&H01111 >.\pwexpire.vbs
echo Dim User >>.\pwexpire.vbs
echo Dim usrflags >>.\pwexpire.vbs
echo Set User = GetObject^("WinNT://./%1,user"^) >>.\pwexpire.vbs
echo usrflags= User.Get^("UserFlags"^) >>.\pwexpire.vbs
echo User.Put "userFlags", usrflags AND ADS_UF_EXPIRE_PASSWD >>.\pwexpire.vbs
echo User.SetInfo >>.\pwexpire.vbs
echo Set User = Nothing >>.\pwexpire.vbs

cscript //nologo .\pwexpire.vbs
if exist .\pwexpire.vbs del .\pwexpire.vbs
)

Share this post


Link to post
Share on other sites
TheFlash428    0
Oops! Sorry about that. Here is a correction:

@echo off
if not [%1]==[] (
echo Const ADS_UF_EXPIRE_PASSWD = ^&H01111 >.\pwexpire.vbs
echo Dim User >>.\pwexpire.vbs
echo Dim usrflags >>.\pwexpire.vbs
echo Set User = GetObject^("WinNT://./%1,user"^) >>.\pwexpire.vbs
echo usrflags= User.Get^("UserFlags"^) >>.\pwexpire.vbs
echo User.Put "userFlags", usrflags AND ADS_UF_EXPIRE_PASSWD >>.\pwexpire.vbs
echo User.SetInfo >>.\pwexpire.vbs
echo Set User = Nothing >>.\pwexpire.vbs

cscript //nologo .\pwexpire.vbs
if exist .\pwexpire.vbs del .\pwexpire.vbs
)

I've been trying to figure out a way to do this myself for a while. Thanks!

Also, if you need to set the "password required", that can be done by:

NET USER [username] /PASSWORDREQ:YES

Share this post


Link to post
Share on other sites
neo    1
From the command line is there a way to uncheck the "Password Never Expires" setting? I am doing this for the LOCAL machine only. I am trying to do this from a bat file that I will be running on computer after it has been syspreped. Any one know they command to do this?

:thumbup try this:

net accounts /maxpwage:unlimited

oh....I missed Sorry

net accounts /maxpwage:<DAYS>

You can write days as desired.

Share this post


Link to post
Share on other sites
dslider    0

I am having an issue with calling this from within another bat script....its in my other bat script liek the following:

C:\windows\securityscript\pwexpire.cmd HelpAssistant

C:\windows\securityscript\pwexpire.cmd Guest

but it throws an error saying the file or directory cant be found...... says the error is at pwexpire.vbs(7,1) .... what am I doing wrong when I call this file?

and yes it is going to the correct directory to run the file...

Share this post


Link to post
Share on other sites
I am having an issue with calling this from within another bat script....its in my other bat script liek the following:

C:\windows\securityscript\pwexpire.cmd HelpAssistant

C:\windows\securityscript\pwexpire.cmd Guest

but it throws an error saying the file or directory cant be found...... says the error is at pwexpire.vbs(7,1) .... what am I doing wrong when I call this file?

and yes it is going to the correct directory to run the file...

OK, I am not able to reproduce this error . :wacko:

I provided you with pwexpire2.vbs for you to run directly

instead of creating it within the batch file.

Your result was:

it just gives me a blank error now.

My result: desired user account(s) set to must change password.

I provided you with AllUserPWExpire.vbs to see if the script

would set all user accounts to must change password.

Your result was:

OK I got it kinda working.... the accounts that are disabled

still dont change and it still throws an error after it runs....

"C:\Windows\securityfolder\pwexpire.vbs(16,9) (null):

The filename, directory name, or volume label syntax is incorrect."

My result: All user accounts set to must change password.

I hope someone else can reproduce the error and shed some

light on a solution.

The attached file contains the two scripts mentioned.

PWExpire.zip

Share this post


Link to post
Share on other sites
dslider    0

the script works on all accounts but the accounts that are already disabled.... if I enable the account the script works without any errors... any one know why this is?

Share this post


Link to post
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


  • Recently Browsing   0 members

    No registered users viewing this page.

×