Solved

WSH VBScript newbie question

Posted on 2004-08-30
7
376 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 22

Expert Comment

by:kristinaw
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
aah, missed that line. sorry bout that.  thanks for your help kris

Trevor
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now