Solved

WSH VBScript newbie question

Posted on 2004-08-30
7
380 Views
Last Modified: 2013-12-03
Hi,

I am trying to create a batch file that sets passwordExpires to false so a user's password will never expire.  I am able to enumerate thru the users, but I can't figure out how to set the passwordExpires.  This is my .vbs so far:

Dim userName
userName = "Trevor Hartman"

Dim users
Set users = GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_useraccount")
For Each user In users
      if user.Name = userName then
            user.PasswordExpires = 1
            WScript.Echo user.PasswordExpires & " - " & user.Name
      end if
Next

Set users = Nothing

This obviously doesn't set the user.Password.Expires = 1 as this is just an emueration...  What is the correct way to do it?

Thanks,
Trevor
0
Comment
Question by:trevorhartman
  • 4
  • 3
7 Comments
 
LVL 22

Expert Comment

by:kristinaw
ID: 11944772
Trev,

can you elaborate on what you're trying to do? you're just trying to set the pass on a local machine for a particular user to never expire? the reason i'm asking is the script would be written differently if you're trying to set the flag for domain accounts.

also, if the computer is a member of a domain, the way you have this written it will enumerate domain accts that have privelidges on the local machine as well.

kris.
0
 
LVL 8

Author Comment

by:trevorhartman
ID: 11944799
Yes I'm trying to set the pass to never expire for a particular user on the local machine.  I don't want to include domain accounts.
-Trevor
0
 
LVL 22

Accepted Solution

by:
kristinaw earned 125 total points
ID: 11945145
trev,

what you have is pretty good. i pulled up some info on the win32_useraccount to see what other attributes were available. see the following:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_useraccount.asp

note the attribute that is 'localaccount'.

you could add some code that says if user.localaccount = true then
user.passwordexpires = 1
user.setinfo '(makes the change effective)

also, the code seems to enumerate the local user accounts first. you might just set the code to break out of the loop whenever you the first user.localaccount = false.

let me know if you want a more specific code example.

kris.

0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 22

Expert Comment

by:kristinaw
ID: 11945161
or, in your example above, once you get a match on that name you could break out of the loop and finish. otherwise it will try to loop through all the domain accts that have privelidge on the machine which would take QUITE some time.

kris.
0
 
LVL 8

Author Comment

by:trevorhartman
ID: 11945187
this:

user.passwordexpires = 1

doesn't actcually set the user.passwordexpires to 1 because it only modifies the temperary user object that is created in the enumeration.  the changes don't reflect on the actual account.  what is the correct way to set these settings?

thanks,
Trevor
0
 
LVL 22

Expert Comment

by:kristinaw
ID: 11945215
Trevor,

that is what the 'user.setinfo' line is for that i added in the above example.

that WILL make the change permanent. try it and see.

kris.
0
 
LVL 8

Author Comment

by:trevorhartman
ID: 11945281
aah, missed that line. sorry bout that.  thanks for your help kris

Trevor
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question