Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

Password Never Expires - Changing automatically

- - - - -

  • Please log in to reply
11 replies to this topic

#1
dslider

dslider

    Newbie

  • Member
  • 15 posts
  • Joined 16-April 08
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, 18 April 2008 - 09:07 AM.



How to remove advertisement from MSFN

#2
neo

neo

    Microsoft MVP - Windows Expert Consumer

  • Member
  • PipPipPipPipPipPip
  • 1,251 posts
  • Joined 31-March 06
  • OS:Windows 7 x64
  • Country: Country Flag

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


#3
dslider

dslider

    Newbie

  • Member
  • 15 posts
  • Joined 16-April 08
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, 17 April 2008 - 07:08 AM.


#4
Scr1ptW1zard

Scr1ptW1zard

    Junior

  • Member
  • Pip
  • 67 posts
  • Joined 05-July 07
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

--== Scr1ptW1zard ==--

#5
dslider

dslider

    Newbie

  • Member
  • 15 posts
  • Joined 16-April 08

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?

#6
Scr1ptW1zard

Scr1ptW1zard

    Junior

  • Member
  • Pip
  • 67 posts
  • Joined 05-July 07
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
)

--== Scr1ptW1zard ==--

#7
TheFlash428

TheFlash428

    Advanced Member

  • Member
  • PipPipPip
  • 456 posts
  • Joined 15-September 05

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

"There are 3 ways to do things: The right way, the wrong way, and the Max Power way!"
"Isn't that the same as the wrong way?"
"Yes--but faster!"

#8
neo

neo

    Microsoft MVP - Windows Expert Consumer

  • Member
  • PipPipPipPipPipPip
  • 1,251 posts
  • Joined 31-March 06
  • OS:Windows 7 x64
  • Country: Country Flag

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.

#9
dslider

dslider

    Newbie

  • Member
  • 15 posts
  • Joined 16-April 08
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...

#10
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,432 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
Read this page as it deals with using VBS script and Local User Accounts.
Vbs Script Local Users


GunSmokingMan



#11
Scr1ptW1zard

Scr1ptW1zard

    Junior

  • Member
  • Pip
  • 67 posts
  • Joined 05-July 07

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.

Attached Files


--== Scr1ptW1zard ==--

#12
dslider

dslider

    Newbie

  • Member
  • 15 posts
  • Joined 16-April 08
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 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users