?
Solved

WSH VBScript newbie question

Posted on 2004-08-30
7
Medium Priority
?
387 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
[X]
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
  • 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 500 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

777 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