stev379 Posted May 11, 2011 Posted May 11, 2011 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!
water Posted May 11, 2011 Posted May 11, 2011 I'm not sure what the lineSet 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
GEOSoft Posted May 11, 2011 Posted May 11, 2011 (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 May 11, 2011 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!"
stev379 Posted May 11, 2011 Author Posted May 11, 2011 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now