# Running install on computers from a file

## Recommended Posts

Heya everyone, i've been digging around a bit and i've gotten close.

I have a script that uninstalls the old AV from a computer and installs our new AV, logs, reports over email, works great.

What I want to do is create a .txt file with the rest of the computer names on the network that need this done. The script goes down the list line by line and executes the function. I know I need to use filereadline but the recursion is a bit past me at the moment. Would anyone be able to help?

If I missed something in the search could you point me to the thread? I may have been looking for this the wrong way.

Thanks

##### Share on other sites

Scratch that, I just had to dig deeper

##### Share on other sites

I've got a snippit I reuse over and over to get computer names and run something on each one. I can put in a comma separated list or read from a comma separated file. It also sets up a progress bar and an output file.

; Get Targets Template
; Author: Graywalker
; Acquires target computer names from text input or text file (comma sepearated)

; Edit all caps items for your script

Const $ScriptName = "" Const$ResultsFile = $ScriptName & "_" & @MON & @MDAY & @HOUR & @MIN & ".csv" ; Error Catching Global$g_eventerror = 0 ; to be checked to know if com error occurs. Must be reset after handling.
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; Install a custom error handler ; Constants Const$ForReading = 0
Const $ForWriting = 2 Const$ForAppending = 1

; Variables
Dim $LogFile,$strPCName, $a = 0,$PCNames, $a_PCNames Dim$ErrorFile
; For Progress Bar
Global $i = 0,$step, $pcc ; Establish Log File to write results to$LogFile = FileOpen($ResultsFile,$ForWriting)
If @error = -1 Then
MsgBox(0, "Error", "ERROR: Unable to initialize requested log file, " & $ResultsFile & ".") FileClose($ResultsFile)
Exit
EndIf ;Err.Number <> 0

; Establish Error File
$ErrorFile = FileOpen($ScriptName & "_ErrorFile.csv", $ForWriting) If @error = -1 Then MsgBox(0, "Error", "ERROR: Unable to initialize requested Error log file.") FileClose($ErrorFile)
Exit
EndIf

; Get the Targets list
$Raw_PCNames = InputBox("Enter Targets", "Computer List or Text File :" & @CRLF, "computer1,computer2,computer3") ; c:\temp\text.txt ; Check for Error Messages Select Case @error = 1 MsgBox(0, "Nnnnnnnnttt", "Uninstall cancelled") Exit Case @error = 3 MsgBox(0, "Nnnnnnnnnntttt", "Input box failed to open, lets try again.") Exit Case StringInStr($Raw_PCNames, "computer1")
MsgBox(0, "Nnnnnnnnnnntttt", "Changing the computer names is required.  Try Again.")
Exit
EndSelect

; Process Targets
Select
Case StringInStr($Raw_PCNames, ".txt")$targets = FileOpen($Raw_PCNames,$ForReading)
$atargets = FileRead($targets)
$a_PCNames = StringSplit($atargets, ",")
Case Else
$a_PCNames = StringSplit($Raw_PCNames, ",")
If Not IsArray($a_PCNames) Then$a_PCNames[0] = 1
$a_PCNames[1] =$PCNames
EndIf
EndSelect

FileWriteLine($LogFile, "HEADERS") ; Set the Step for Progress Bar$step = 100/$a_PCNames[0] ; Initalize progress bar ProgressOn("PROGRESSTITLE", "Checking Computers", "Please wait...", 2, -2, 18) ; Set Progress bar with number of records to check ProgressSet($i, "Checking " & $a_PCNames[0] & " Computers", "Please wait...") Do$pcc = $pcc + 1$a = $a + 1 If$a = $a_PCNames[0] + 1 Then ExitLoop EndIf$strPCName = $a_PCNames[$a]
$i = Round($i + $step, 2) ProgressSet($i, $pcc & " of " &$a_PCNames[0], "Working on " & $strPCName) ; check to see if the computer is available, if so - launch function If FileExists("\\" &$strPCName & "\c$\*.*") Then FUNCTIONTITLE($strPCName)
Else
FileWriteLine($LogFile,$strPCName & ", Could not connect")
EndIf

Until $a =$a_PCNames[0] + 1

; Tidy Up
FileClose($LogFile) FileClose($ErrorFile)

Exit

; --------- FUNCTIONS --------- Where the work takes place

Func FUNCTIONTITLE($strPCName) EndFunc ; This is someone else's custom COM error handler - and I can't remember where I got it!! Func MyErrFunc() Msgbox(0,"AutoItCOM Error","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB &$oMyError.description    & @CRLF & _
"err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & hex($oMyError.number,8)  & @CRLF & _
"err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB &$oMyError.scriptline     & @CRLF & _
"err.source is: "         & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB &$oMyError.helpfile       & @CRLF & _
"err.helpcontext is: "    & @TAB & $oMyError.helpcontext _ )$HexNumber = Hex($oMyError.number, 8) FileWriteLine($ErrorFile, $strPCName & "," &$oMyError.description & "," & $HexNumber & ", Line " &$oMyError.scriptline & "," & $oMyError.windescription)$g_eventerror = 1 ; something to check for when this function returns
EndFunc   ;==>MyErrFunc
Edited by Graywalker

##### Share on other sites

Graywalker, just wanted to thank you for posting your snippet. I've been using AutoIt for about 2 weeks and I learned a lot from your snippet. Good examples of lots of things.

Thanx again

## Create an account

Register a new account