Sign in to follow this  
Followers 0
kevinward13

WMI Local user help

2 posts in this topic

#1 ·  Posted (edited)

I have some laptops that are not connected to the network and are not part of a domain.

However I need to configure some local accounts, admin and non-admin to be the same across the board.

So i have been trying to get some of the tasks automated so i can push this work off to non technical people.

$strComputer = @ComputerName
Global $Local_User = "JOHNJOHN"
Global $Local_Admin = ""
Dim $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
Dim $colItems = $objWMIService.ExecQuery("Select * from Win32_UserAccount Where Name =" & $Local_User) ; Where LocalAccount = True")
For $objItem In $colItems
Msgbox(0, "", "Account Type: " & $objItem.AccountType)
Msgbox(0, "", "Caption: " & $objItem.Caption)
Msgbox(0, "", "Description: " & $objItem.Description)
Msgbox(0, "", "Disabled: " & $objItem.Disabled)
Msgbox(0, "", "Domain: " & $objItem.Domain)
Msgbox(0, "", "Full Name: " & $objItem.FullName)
Msgbox(0, "", "Local Account: " & $objItem.LocalAccount)
Msgbox(0, "", "Lockout: " & $objItem.Lockout)
Msgbox(0, "", "Name: " & $objItem.Name)
Msgbox(0, "", "Password Changeable: " & $objItem.PasswordChangeable)
Msgbox(0, "", "Password Expires: " & $objItem.PasswordExpires)
Msgbox(0, "", "Password Required: " & $objItem.PasswordRequired)
Msgbox(0, "", "SID: " & $objItem.SID)
Msgbox(0, "", "SID Type: " & $objItem.SIDType)
Msgbox(0, "", "Status: " & $objItem.Status)
Next

I have been trying to get the code to work with just providing the accounts i want to change. But for some reason the line Dim $colItems = $objWMIService.ExecQuery("Select * from Win32_UserAccount Where Name =" & $Local_User) ; Where LocalAccount = True") will not give me what i need.

Even when i change the query to "Select * from Win32_UserAccount Where Name = JOHNJOHN)

I do not get anything returned. script runs and exits with no errors

I can change the query to ("Select * from Win32_UserAccount Where LocalAccount = True") and I get the entire enumeration of all the local accounts.

How can i go about just providing the two accounts i want to have changed?

ok got that part figured out, now for the second part.

Msgbox(0, "", "Password Changeable: " & $objItem.PasswordChangeable)

I would like to be able to change this setting back and forward as i see fit.

In most cases it would return "TRUE" that the user/admin can change the password. But I would like to change this to "FALSE" on a case by case basis. So how would I direct the script to "Check the box" in the user account properties where "USER CANNOT CHANGE PASSWORD" ?

So far I have tried this

If $objItem.PasswordChangeable = True Then $objItem.PasswordChangeable = False $objItem.SetInfo EndIf

as well as

If $objItem.PasswordChangeable = True Then ;$objItem.PasswordChangeable = False $objItem.SetInfo(False) EndIf

I figured it out again. Sometimes all i take is me just posting it here and reading it to myself again and again

If $objItem.PasswordChangeable = True Then
Run(@ComSpec & " /c net user " & $Local_User & " /passwordchg:no", "", @SW_HIDE)
EndIf

I'm a genius in my world....who knew? :D

Edited by kevinward13

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

MEH!

Fingered it out.....single quotes !

("Select Name, Lockout, PasswordChangeable, PasswordExpires, PasswordRequired from Win32_UserAccount WHERE Name = '" & $Local_User & "'")
Edited by kevinward13

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0