schilbiz Posted April 9, 2008 Posted April 9, 2008 (edited) @ All, I tried to come up with a simple way to update Citrix client information and came up with this, it seems to work fine. How could it be improved on? One thing I am not sure about is if the FileClose($file) is in the right spot is there a better/proper location? As you will notice I am using a .msi and it is configured to only show the splash screen and progress, then close at completion. Any input is appreciated, thanks. #RequireAdmin const $file = FileOpen("C:\Program Files\Citrix\ICA Client\version.dat", 0) const $line = FileReadLine($file) If FileExists("C:\Program Files\Citrix\ICA Client\version.dat") Then While 1 If ($line) = ("10.200.2650") Then Exitloop ElseIf ($line) <> ("10.200.2650") Then Run(@ComSpec & " /c " & '\\server\files\Citrix\Client_10.2\ica32pkg.msi', "", @SW_HIDE) Exit FileClose($file) EndIf WEnd Else Exit EndIf Edited April 9, 2008 by schilbiz
ResNullius Posted April 10, 2008 Posted April 10, 2008 (edited) This makes a little more sense to me: #RequireAdmin $VerFile = "C:\Program Files\Citrix\ICA Client\version.dat" ;first, lets check to see if the file exists before we open or try to read from it If FileExists($VerFile) Then $version = FileReadLine($VerFile) ; since we're only reading one line, just as efficient (with less code) to FileReadLine as ; it is to FileOpen, Read, then FileClose If Not @error Then ; check to see if the FileReadLine failed If StringStripWS($version, 3) <> "10.200.2650" Then ;added a StringStrip just in case extraneous spaces were introduced ShellExecute("\\server\files\Citrix\Client_10.2\ica32pkg.msi") ;shell execute does away with the need for a convoluted command line that may fail with no error message EndIf MsgBox(16, "OH-OH", "Can't read the version.dat file." & @CRLF & "It exists, but I can't read it :-(") EndIf Else MsgBox(16, "OH-OH", "Can't find the version dat file: " & @CRLF & @CRLF & $VerFile & @CRLF & @CRLF & "exiting...") EndIf I also chose variables that are a little more descriptive to our purpose. "$file" & "$line" are good temporary/placeholder variables when you're dealing with a large list of files for processing, or a great number of lines. But, we're only dealing with one file and one line, so I went with "$VerFile" & "$version". Also, even if you were going to use the FileOpen(), read, then FileClose() methods, there would be no need to declare them as constants in this scenario. Edited April 10, 2008 by ResNullius
schilbiz Posted April 10, 2008 Author Posted April 10, 2008 Nice ideas, thanks ResNullius, I like how you did it. The reason I used const at the start is because I was thinking of an elaborate way of doing it where it would verify multiple versions of the client but found it didn't need to be that difficult and then just left it because it worked. Thats why I ask, I like to see how things can be done differently and improved upon, thanks for your input.
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