Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

WSH VBScript newbie question

Posted on 2004-08-30
7
382 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Microsoft Query from QuickBooks 9 72
wordpress limitations 4 124
Example of WebAPI 7 33
Need an intro to -- .Net SQL Authorization Manager 7 90
This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
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 …
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

861 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