#122820 - 2004-07-13 11:48 PM
GetFileVersion not working right
|
FieR0
Fresh Scripter
Registered: 2004-07-13
Posts: 5
|
I have a script that I use for installing MS updates on computers. I am implementing something to check actual file version, due to some of the updates not creating reg files when slipstreamed into the install. I wrote a function to perform what i need, and it works fine. When i move it into a different script (so it can be a more universal), it always says it cant find the file - even though I display the contents and they are fine. Here's a snippet of the script. Please let me know if you need more. Here's how it flows. I call Script A. It then calls Script B for checking. Anytime an update is needed, Script E is called (and performs the update). It works in Script B, but not in Script E. I use all Calls and Returns.
Code:
Function UpdatedFileList() $ArraySize = 0 $filename = "$ScriptDir\fileupdatelist.csv" ; This file is in the format: KB######,Filename,FileVersion If Open(1,$filename) = 0 $line = ReadLine(1) While @error = 0 $x = Left($line,8) If $x = $KBNumber $ArraySize = $ArraySize + 1 EndIf $line = ReadLine(1) Loop $=Close(1) EndIf If $ArraySize == 0 Return EndIf Dim $array[$ArraySize-1,1] $ArrayCount = 0 If Open(1,$filename) = 0 $line = ReadLine(1) While @error = 0 $x = Left($line,8) If $x = $KBNumber
; $=MessageBox("ArrayCount is $ArrayCount","$KBNumber",0) $LastComma = InStrRev($line,',') $array[$ArrayCount,0] = SubStr($line,10,$LastComma - 10) $array[$ArrayCount,1] = Right($line, Len($line) - $LastComma) $ArrayCount = $ArrayCount + 1 EndIf $line = ReadLine(1) Loop $=Close(1) EndIf
For $x = 0 to Ubound($array) ;$ArrayCount-1 ; $FileNameCheck = $array[$x,0] $FileVerCheck = $array[$x,1] $=MessageBox($FileNameCheck + '-' + GetFileVersion($FileNameCheck),"$KBNumber",0) ; ? "$array[$x,0]-$FileNameCheck;$array[$x,1]-$FileVerCheck" If GetFileVersion($FileNameCheck) < $FileVerCheck $NeedUpdate = 'Y' ? "$FileNameCheck;$FileVerCheck" EndIf Next $UpdatedFileList = $NeedUpdate EndFunction
|
|
Top
|
|
|
|
#122822 - 2004-07-14 12:11 AM
Re: GetFileVersion not working right
|
FieR0
Fresh Scripter
Registered: 2004-07-13
Posts: 5
|
More info: Here is the error message, and what is located in the array: These files do exist.
Error 2 - The system cannot find the file specified. %SystemRoot%\System32\Catsrv.dll;2000.2.3511.0 Error 2 - The system cannot find the file specified. %SystemRoot%\System32\Catsrvut.dll;2000.2.3511.0 Error 2 - The system cannot find the file specified. %SystemRoot%\System32\Clbcatex.dll;2000.2.3511.0 Error 2 - The system cannot find the file specified. %SystemRoot%\System32\Clbcatq.dll;2000.2.3511.0 Error 2 - The system cannot find the file specified. %SystemRoot%\System32\Colbact.dll;2000.2.3511.0 Error 2 - The system cannot find the file specified. %SystemRoot%\System32\com\Comadmin.dll;2000.2.3511.0
I did hardcode a directory, and that one worked. But like i said, this exact script one call above works perfectly. I did not make any changes to the function.
|
|
Top
|
|
|
|
#122824 - 2004-07-14 06:56 AM
Re: GetFileVersion not working right
|
FieR0
Fresh Scripter
Registered: 2004-07-13
Posts: 5
|
Ok, added the ExpandEnvironmentVars($FileNameCheck)
Now here's some of the log. I have no idea why this isn't working?
Error 2 - The system cannot find the file specified. C:\WINNT\System32\Catsrv.dll %SystemRoot%\System32\Catsrv.dll;2000.2.3511.0 Error 2 - The system cannot find the file specified. C:\WINNT\System32\Catsrvut.dll %SystemRoot%\System32\Catsrvut.dll;2000.2.3511.0 Error 2 - The system cannot find the file specified. C:\WINNT\System32\Clbcatex.dll %SystemRoot%\System32\Clbcatex.dll;2000.2.3511.0 Error 2 - The system cannot find the file specified. C:\WINNT\System32\Clbcatq.dll %SystemRoot%\System32\Clbcatq.dll;2000.2.3511.0 Error 2 - The system cannot find the file specified. C:\WINNT\System32\Colbact.dll %SystemRoot%\System32\Colbact.dll;2000.2.3511.0 Error 2 - The system cannot find the file specified. C:\WINNT\System32\com\Comadmin.dll %SystemRoot%\System32\com\Comadmin.dll;2000.2.3511.0
|
|
Top
|
|
|
|
#122826 - 2004-07-14 11:26 PM
Re: GetFileVersion not working right
|
FieR0
Fresh Scripter
Registered: 2004-07-13
Posts: 5
|
Here's one a little smaller (i hope).
It doesn't seen to find the file using the %Systemroot% variable.
Code:
Function TempArray($KBNumber) Break on $arrayfilehandle = FreeFileHandle() $filename = "$ScriptDir\UpdateFileList\" + $KBNumber + ".csv" If Open($arrayfilehandle,$filename) = 0 $line = ReadLine($arrayfilehandle) While @error = 0 $array = Split($line,",") $FileNameCheck = $array[0] $FileVerCheck = $array[1] If GetFileVersion($FileNameCheck,"FileVersion") < $FileVerCheck ? 'Error '+@ERROR+' - '+@SERROR ? "$FileNameCheck;$FileVerCheck" Sleep(1) $NeedUpdate = 'Y' $TempArray = $NeedUpdate EndIf $line = ReadLine($arrayfilehandle) Loop $= Close($arrayfilehandle) endif EndFunction
Here's what the .csv file looks like. %SystemRoot%\System32\Catsrv.dll,2000.2.3511.0 %SystemRoot%\System32\Catsrvut.dll,2000.2.3511.0 %SystemRoot%\System32\Clbcatex.dll,2000.2.3511.0
And here's some logging information: Error 2 - The system cannot find the file specified. %SystemRoot%\System32\Catsrv.dll;2000.2.3511.0 C:\WINNT\System32\Catsrv.dll Error 2 - The system cannot find the file specified. %SystemRoot%\System32\Catsrvut.dll;2000.2.3511.0 C:\WINNT\System32\Catsrvut.dll Error 2 - The system cannot find the file specified. %SystemRoot%\System32\Clbcatex.dll;2000.2.3511.0 C:\WINNT\System32\Clbcatex.dll
|
|
Top
|
|
|
|
#122828 - 2004-07-14 11:58 PM
Re: GetFileVersion not working right
|
FieR0
Fresh Scripter
Registered: 2004-07-13
Posts: 5
|
Yes, that was the problem, although when i tried your line it gave me an out of bounds error. So instead i'm doing this: $FileNameCheck = ExpandEnvironmentVars($array[0])
I had read the help, and one of the Expressions had the %USERNAME% field in it, so i thought you could just use that without anything else.
Thanks.
So here's the updated code (smaller than the original too). Code:
Function TempArray($KBNumber) Break on $arrayfilehandle = FreeFileHandle() $filename = "$ScriptDir\UpdateFileList\" + $KBNumber + ".csv" If Open($arrayfilehandle,$filename) = 0 $line = ReadLine($arrayfilehandle) While @error = 0 $array = Split($line,",") $FileNameCheck = ExpandEnvironmentVars($array[0]) $FileVerCheck = $array[1] If GetFileVersion($FileNameCheck,"FileVersion") < $FileVerCheck $NeedUpdate = 'Y' Exit EndIf $line = ReadLine($arrayfilehandle) Loop $= Close($arrayfilehandle) EndIf $TempArray = $NeedUpdate EndFunction
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 837 anonymous users online.
|
|
|