lafafmentvotre Posted December 11, 2012 Posted December 11, 2012 Hi everybody I need some help to finalize a script to rename many computers with netdom command. I block on array I have a file inf like this (Rename_Computer_Auto.inf) : oldcomputer_name_01, newcomputer_name_01 oldcomputer_name_02, newcomputer_name_02 oldcomputer_name_03, newcomputer_name_03 oldcomputer_name_04, newcomputer_name_04 ...... And here is my script but i have problem tu use array expandcollapse popupBreak(1) #region AUTOIT VARIABLES #include #include #include #include #include #include #endregion #region SCRIPT VARIABLES Local $NewComputerName,$OldComputerName,$avArray Local $ver="1.0" Local $blank='' Local $List=FileOpen('Rename_Computer_Auto.inf', 0) $log_file='Rename_Computer_Auto_'&@YEAR&'-'&@MON&'-'&@MDAY&'.log' $arraylist="" Local $DomainName="my domain" Local $AdminName="my account" Local $Password="my password" #endregion #region SCRIPT $GuiRun=GuiCreate("", 300, 60, -1, -1, $WS_POPUPWINDOW) $label1=GUICtrlCreateLabel("Renaming in progress for :", 0, 10, 300, 20, $SS_CENTER) $label2=GUICtrlCreateLabel("", 0, 30, 300, 20,$SS_CENTER) GUICtrlSetFont(-1, 9, 800) GUISetState(@SW_SHOW,$GuiRun) For $i = 1 To UBound($arraylist) - 1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $avArray=StringSplit(FileReadLine($List,$i),",") If @error = -1 Then ExitLoop $OldComputerName=_ArrayToString($avArray, @TAB, 1, 1) $NewComputerName=_ArrayToString($avArray, @TAB, 2, 2) GUICtrlSetData($label2,$OldComputerName) $ping=Ping($OldComputerName) If $ping Then RunAs($AdminName,$DomainName,$Password,0,@ComSpec & " /c netdom renamecomputer "&$OldcomputerName&" /NewName:"&$NewComputerName&" /ud:"&$DomainName&"\"&$AdminName&" /PasswordD:"&$Password&" /Force") $intFile = FileOpen($log_file, 1) FileWriteLine($intFile, $OldcomputerName&' was renamed '&$NewComputerName&' on '&@YEAR&'-'&@MON&'-'&@MDAY&' at '&@HOUR&':'&@MIN&':'&@SEC) FileClose($intfile) Else $intFile = FileOpen($log_file, 1) FileWriteLine($intFile, $OldcomputerName&' was not renamed '&$NewComputerName&' because Host is offline or unreachable') FileClose($intfile) EndIf Next GUIDelete($GuiRun) Please could You help me ? Sorry for my english
water Posted December 11, 2012 Posted December 11, 2012 Replace line For $i = 1 To UBound($arraylist) - 1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<withFor $i = 1 To 99999You exit the loop as soon as the line you want to read doesn't exist. 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
Exit Posted December 11, 2012 Posted December 11, 2012 (edited) you define$arraylist=""as an empty string (not an array)and then you use it as an array (ubound)For $i = 1 To UBound($arraylist)First fill the array and then use itEdit: Water has the more speedy fingers. Edited December 11, 2012 by Exit App: Au3toCmd UDF: _SingleScript()
lafafmentvotre Posted December 11, 2012 Author Posted December 11, 2012 Hello Thank You It's ok but I do not go out of the loop :-(
lafafmentvotre Posted December 11, 2012 Author Posted December 11, 2012 Hello Exit This is my problem, I do not control the array
water Posted December 11, 2012 Posted December 11, 2012 (edited) You are checking the wrong @error. It's the error value of StringSplit not of FileReadLine. Change line$avArray = StringSplit(FileReadLine($List, $i), ",") If @error = -1 Then ExitLoopto$Line = FileReadLine($List, $i) If @error = -1 Then ExitLoop $avArray = StringSplit($Line, ",") Edited December 11, 2012 by water 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
Exit Posted December 11, 2012 Posted December 11, 2012 (edited) $avArray=StringSplit(FileReadLine($List,$i),",") If @error = -1 Then ExitLoop Stringsplit never returns @error = -1 you have to separate filereadline and stringsplit. First test filereadline error and exit if <> 0 Edit: Water had the more speedy fingers again. Edited December 11, 2012 by Exit App: Au3toCmd UDF: _SingleScript()
lafafmentvotre Posted December 11, 2012 Author Posted December 11, 2012 Argggghhhhh It is difficult to understand with all your answers I do not understand what I write or remove
water Posted December 11, 2012 Posted December 11, 2012 Reply #6 and #7 describe the same problem. Do what I suggest in post #6 and the problem should be solved. 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
water Posted December 11, 2012 Posted December 11, 2012 Glad the problem could be solved BTW: Maybe you should take some time to brush up your AutoIt knowledge. That problem was easily spotted by two users within two minutes. So it should be as easy for you too 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
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