Jump to content
Sign in to follow this  

Change Local Admin Password

Recommended Posts

We need to change the local Admin password on our network nodes. I can use the "Net User" command inside an AutoIT script, but because of an unique setup we have here and another system we use to push things, it would be better if we could convert the VBS version into AutoIT, pack it in an exe and send with our pushing system.

I've tried re-writting the code below in AutoIT and it fails. Anyone have this converted already or do you have any tips or suggestions?

Dim strComputer, CPU, objuser, wsh

strComputer = "."
Set CPU = GetObject("WinNT://" & strComputer & ",Computer")
Set objuser = CPU.GetObject("User", "Administrator")

Set wsh = Wscript.CreateObject("Wscript.Shell")
objUser.SetPassword "ENTER PASSWORD HERE"

The code below errors with "Variable must be of type "Object"."

I'm sure the $wsh line is wrong, but don't know the answer.

I'm not sure if anything else needs to be changed.

Dim $strComputer, $CPU, $objUser, $wsh, $Wscript

$strComputer = "."
$CPU = ObjGet("WinNT://" & $strComputer & ",Computer")
$objUser = $CPU.GetObject("User", "Administrator")

$wsh = $Wscript.CreatObject("Wscript.Shell")
$objUser.SetPassword "Password"

Thanks for any help or suggestions!

Share this post

Link to post
Share on other sites

I'm not sure what the line

Set wsh = Wscript.CreateObject("Wscript.Shell")
is needed for.

Could you remove the line and test again?

My UDFs and Tutorials:


Active Directory (NEW 2020-10-10 - Version - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-12-15 - Version - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2020-06-27 - Version - Download
Outlook Tools (2019-07-22 - Version - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version - Download - General Help & Support - Wiki

ADO - Wiki, WebDriver - Wiki


Share this post

Link to post
Share on other sites

He can't remove that line. I'm not sure if that can be removed or not. There doesn't appear to be any further references to it so perhaps it can. If not then the syntax will be as below.

$wsh = ObjCreate("Wscript.Shell")
Edited by GEOSoft


Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver: - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post

Link to post
Share on other sites

Thanks! To both of you.

I commented out the wsh line and the script below does work now. Locally run anyway. It's not changing the PW when I push it, but that's a different issue to be addressed by other means.


Dim $strComputer, $CPU, $objUser, $Wscript, $adminLocal ;, $wsh

;Get the local administrator name in case it is not already set to the standard
$adminLocal = GetAdministratorName(@ComputerName)
$strComputer = "."
$CPU = ObjGet("WinNT://" & $strComputer & ",Computer")
$objUser = $CPU.GetObject("User", $adminLocal)

;$wsh = ObjCreate("Wscript.Shell")
$objUser.SetPassword ("ENTERPASSWORDHERE")

;  Debugging

Func GetAdministratorName($ComputerName)
    Dim $UserSID, $oWshNetwork, $oUserAccount
    $objWMIService = objGet( "winmgmts:{impersonationLevel=impersonate}!//"  & $ComputerName & "/root/cimv2")
    $oUserAccounts = $objWMIService.ExecQuery("Select Name, SID from Win32_UserAccount WHERE Domain = '" & $ComputerName & "'")
    For $oUserAccount In $oUserAccounts
        If StringLeft($oUserAccount.SID, 9) = "S-1-5-21-" And _
            StringRight($oUserAccount.SID, 4) = "-500" Then
            Return $oUserAccount.Name

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...