• Announcements

    • xper

      MSFN Sponsorship and AdBlockers!   07/10/2016

      Dear members, MSFN is made available via subscriptions, donations and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, become a site sponsor and ads will be disabled automatically and by subscribing you get other sponsor benefits.
dslider

Password Never Expires - Changing automatically

12 posts in this topic

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
0

Share this post


Link to post
Share on other sites
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

0

Share this post


Link to post
Share on other sites

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
0

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

0

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

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

0

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
)

0

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
)

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

0

Share this post


Link to post
Share on other sites
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.

0

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...

0

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

0

Share this post


Link to post
Share on other sites

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?

0

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.