Jump to content
Sign in to follow this  

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? :D I may have been looking for this the wrong way.


Share this post

Link to post
Share on other sites

Scratch that, I just had to dig deeper :D


Share this post

Link to post
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 & ".")
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.")

; 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
    Case @error = 1
        MsgBox(0, "Nnnnnnnnttt", "Uninstall cancelled")
    Case @error = 3
        MsgBox(0, "Nnnnnnnnnntttt", "Input box failed to open, lets try again.")
    Case StringInStr($Raw_PCNames, "computer1")
        MsgBox(0, "Nnnnnnnnnnntttt", "Changing the computer names is required.  Try Again.")

; Process Targets
    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

; EDIT the Headers for your output to the LogFile
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...")

    $pcc = $pcc + 1
    $a = $a + 1
    If $a = $a_PCNames[0] + 1 Then
    $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
        FileWriteLine($LogFile, $strPCName & ", Could not connect")

Until $a = $a_PCNames[0] + 1

; Tidy Up


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



; 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 this post

Link to post
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

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.