Jump to content

Validation


Shawndt
 Share

Recommended Posts

I am trying to write a vaildation script by checking directories for install paths. The script is suppose to write to a log file but it is only writing once.

So for instance it writes whether IE8 is installed that's it. Even though there are other software installed that it should be seeing and appending to the same log.

code

#INCLUDE <File.au3>

#INCLUDE <Date.au3>

$Validation = "\PROGRAMS\VALIDATION\"

;Microsoft Office 2007 Validation

If FileExists("C:\Program Files\Microsoft Office\Office12") then

_FileCreate($Validation & "\" & @UserName & ".log")

FileWriteLine($Validation & "\" & @UserName & ".log", _Now())

FileWriteLine($Validation & "\" & @UserName & ".log", "Microsoft Office 2007 Installed")

Else

FileWriteLine($Validation & "\" & @UserName & ".log", _Now())

FileWriteLine($Validation & "\" & @UserName & ".log", "Microsoft Office 2007 Failed")

EndIf

;Afaria Validation

If FileExists("C:\Program Files\AClient") then

_FileCreate($Validation & "\" & @UserName & ".log")

FileWriteLine($Validation & "\" & @UserName & ".log", _Now())

FileWriteLine($Validation & "\" & @UserName & ".log", "Afaria 6.5 Installed")

Else

FileWriteLine($Validation & "\" & @UserName & ".log", _Now())

FileWriteLine($Validation & "\" & @UserName & ".log", "Afaria 6.5 failed")

EndIf

;Siebel 7.8

If FileExists("C:\Program Files\Siebel7.8") then

_FileCreate($Validation & "\" & @UserName & ".log")

FileWriteLine($Validation & "\" & @UserName & ".log", _Now())

FileWriteLine($Validation & "\" & @UserName & ".log", "Siebel 7.8 Installed")

Else

FileWriteLine($Validation & "\" & @UserName & ".log", _Now())

FileWriteLine($Validation & "\" & @UserName & ".log", "Siebel 7.8 failed")

Endif

;Imagine and Workflow 2.0 install

If FileExists("C:\Program Files\NRS") then

_FileCreate($Validation & "\" & @UserName & ".log")

FileWriteLine($Validation & "\" & @UserName & ".log", _Now())

FileWriteLine($Validation & "\" & @UserName & ".log", "IMG and Workflow Installed")

Else

FileWriteLine($Validation & "\" & @UserName & ".log", _Now())

FileWriteLine($Validation & "\" & @UserName & ".log", "IMG and Workflow failed")

Endif

;Symantec Vontu DLP Endpoint

If FileExists("C:\Program Files\Symantec\Endpoint Agent") then

_FileCreate($Validation & "\" & @UserName & ".log")

FileWriteLine($Validation & "\" & @UserName & ".log", _Now())

FileWriteLine($Validation & "\" & @UserName & ".log", "Vontu DLP ENDPOINT Installed")

Else

FileWriteLine($Validation & "\" & @UserName & ".log", _Now())

FileWriteLine($Validation & "\" & @UserName & ".log", "Vontu DLP ENDPOINT Installed failed")

Endif

If FileExists(@UserProfileDir & "\Favorites\NF Retirement Plans Favorites") then

_FileCreate($Validation & "\" & @UserName & ".log")

FileWriteLine($Validation & "\" & @UserName & ".log", _Now())

FileWriteLine($Validation & "\" & @UserName & ".log", "NRS IE Favs Installed")

Else

FileWriteLine($Validation & "\" & @UserName & ".log", _Now())

FileWriteLine($Validation & "\" & @UserName & ".log", "NRS IE Favs Failed")

EndIf

code

Link to comment
Share on other sites

You may want to check if your log file exists before-hand and only create it once (it may be overwriting itself?)

Also check for @error to see if it is having problems writing to your log file.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

someone asked recently for something remarkably similar, perhaps you can check for the install information from the registry instead? in that case this may come in handy

_LogInstalledPrograms(@DesktopDir & "\" & @UserName & ".txt")

Func _LogInstalledPrograms($_outputFile)
    Local $_uninstallKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    Local $_pCount = 1
    Local $_programDisplayName, $_programDisplayVersion
    Local $_programKey = RegEnumKey($_uninstallKey, $_pCount)
    While ($_programKey <> "")
        $_pCount += 1
        $_programDisplayName = RegRead($_uninstallKey & "\" & $_programKey, "DisplayName")
        If ($_programDisplayName <> "") Then
            $_programDisplayVersion = RegRead($_uninstallKey & "\" & $_programKey, "DisplayVersion")
            If ($_programDisplayVersion == "") Then
                $_programDisplayVersion = "Unknown"
            EndIf
            FileWriteLine($_outputFile, $_programDisplayName & "; Version:" & $_programDisplayVersion)
        EndIf
        $_programKey = RegEnumKey($_uninstallKey, $_pCount)
    WEnd
EndFunc   ;==>_LogInstalledPrograms
Link to comment
Share on other sites

The problem is that everytime you use _FileCreate you're zeroing out the file, in effect you're recreating the file using that command.

You should be using FileOpen, and assigning the file handle created to a variable, write to the file using FileWriteLine and the file handle in that variable. This way you won't be deleting the contents of the file every time. I see no point to using the function _FileCreate for anything at all, it's just a shorthand way of opening a file, and testing to see if it's been opened and writable, you could probably do the same thing yourself without deleting the contents of your file everytime.

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...