Jump to content

How to make script faster with FileGetVersion on remote computers


antmar904
 Share

Recommended Posts

Hi,

I need to get the file version of a certain file on a large number of remote computers.  My scrip is too slow most likely because of the ping.  How can I make this much faster?  TIA!

Is there a way to add some type of multi thread processing to this?

 

#include <Array.au3>
#include <AutoITConstants.au3>
#include <Timers.au3>
#include <File.au3>
#RequireAdmin

OnAutoItExitRegister("WriteLog")

Local $ComputerList = @ScriptDir & "\TrendCheckADComputerNames.txt", $LogFile = @ScriptDir & "\" & @MON & "" & @MDAY & "" & @YEAR & "_" & @HOUR & "_" & @MIN & "_TrendAudit.csv", $sPC = FileReadToArray($ComputerList)


If Not FileExists($ComputerList) Then
    MsgBox(48, "Error", "Missing the computer list file : " & @CRLF & $ComputerList & @CRLF & @CRLF & "Please make sure it exist then run the script again.")
    Exit
EndIf

;_ArrayDisplay($sPC, "Computer List") ;Debug

;Create Array
Global $Array_Base[2]
Global $Array = $Array_Base

_ArrayAdd($Array, "ComputerName" & "," & "Trend Version")

For $i = 0 To UBound($sPC) - 1
    If Ping($sPC[$i]) Then
        Local $sVersion = FileGetVersion('\\' & $sPC[$i] & '\C$\Program Files\Trend Micro\OfficeScan Client\Ntrtscan.exe', "FileVersion")
        Local $sVersion2 = FileGetVersion('\\' & $sPC[$i] & '\C$\Program Files (x86)\Trend Micro\OfficeScan Client\Ntrtscan.exe', "FileVersion")
        _ArrayAdd($Array, $sPC[$i] & "," & $sVersion & $sVersion2)
    Else
        _ArrayAdd($Array, $sPC[$i] & "," & "Offline")
    EndIf
Next

WriteLog()

Func WriteLog()
_FileWriteFromArray($LogFile, $Array)
Exit
EndFunc

 

Edited by antmar904
Link to comment
Share on other sites

You could have a setup where you have one (parent) script launch a bunch of (child) scripts through the command line... basically use the inside of your loop as the child script, pass the params through, and have it write the results to a specific file... an ini file under a Section named as the PC?

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

It would go faster without the Ping, just check for @error to be set after the FileGetVersion command and see if it failed or not.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

6 minutes ago, antmar904 said:

How would I do that when checking two different file path locations?

Check for an error after each one, if both error out then the computer is offline or the files just aren't there. Considering the fact you're not doing any checks in your original script to see if FileGetVersion actually returns a valid version number, at least this way you'll know enough not to write bogus information into your array as you're doing now.

The way you have it written now, as long as the computer responds to a ping, then you're adding something to your array, regardless of whether the file is there or not.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

25 minutes ago, BrewManNH said:

Check for an error after each one, if both error out then the computer is offline or the files just aren't there. Considering the fact you're not doing any checks in your original script to see if FileGetVersion actually returns a valid version number, at least this way you'll know enough not to write bogus information into your array as you're doing now.

The way you have it written now, as long as the computer responds to a ping, then you're adding something to your array, regardless of whether the file is there or not.

Not working:

For $i = 0 To UBound($sPC) - 1
    Local $sVersion = FileGetVersion('\\' & $sPC[$i] & '\C$\Program Files\Trend Micro\OfficeScan Client\Ntrtscan.exe', "FileVersion")
    If @error Then
        Local $sVersion2 = FileGetVersion('\\' & $sPC[$i] & '\C$\Program Files (x86)\Trend Micro\OfficeScan Client\Ntrtscan.exe', "FileVersion")
    ElseIf @error Then
        _ArrayAdd($Array, $sPC[$i] & "," & "Offline or No Trend")
    Else
    _ArrayAdd($Array, $sPC[$i] & "," & $sVersion & $sVersion2)

 

Link to comment
Share on other sites

2 minutes ago, antmar904 said:

Not working:

Well... that's not helpful. Maybe a bit of description? How exactly isn't it working?

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

5 minutes ago, antmar904 said:

nothing is getting written to the log file

Well, from the snippet you posted above, that makes sense, there's not even a 'Next'. If you mean you replaced the loop with that, it doesn't make sense, at least the header of the array should be written to the log file. You might want to throw some FileExists checks in there so you can make sure that the computers are still connected.

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

Maybe something like this would work? Not tested, and may need to be adjusted to fit your needs.

For $i = 0 To UBound($sPC) - 1
     Local $sVersion2 = "0.0.0", $sVersion = FileGetVersion('\\' & $sPC[$i] & '\C$\Program Files\Trend Micro\OfficeScan Client\Ntrtscan.exe', "FileVersion") ; check programfiles for the file version
     If @error Then ; first one not found
          $sVersion2 = FileGetVersion('\\' & $sPC[$i] & '\C$\Program Files (x86)\Trend Micro\OfficeScan Client\Ntrtscan.exe', "FileVersion") ; Check programfiles (x86) for the file
          If @error Then ; still not found
               _ArrayAdd($Array, $sPC[$i] & "," & "Offline or No Trend") ; add to the array that it doesn't exist in either location
               ContinueLoop
         EndIf
     EndIf
     _ArrayAdd($Array, $sPC[$i] & "," & $sVersion & " : " & $sVersion2) ; add the version information for the found version
 
Next

 

NOTE: I have edited the original script. The original script wouldn't have written the correct version number into the array if it had been found in the first test, and would have errored due to the variable $sVersion 2 being declared inside the second If conditional check. This declares that variable before the first test, and shouldn't have the problem.

Edited by BrewManNH
Edited the script

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...