Sign in to follow this  
Followers 0
stev379

Change Local Admin Password

4 posts in this topic

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"
objUser.SetInfo

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"
$objUser.SetInfo

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:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

George

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:3.0.1.13) - 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.

Thanks!!

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")
$objUser.SetInfo

;  Debugging
;MsgBox(0,'',$admin)

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
        Endif
    Next
EndFunc

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