Page 1 of 1 1
Topic Options
#122820 - 2004-07-13 11:48 PM GetFileVersion not working right
FieR0 Offline
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
#122821 - 2004-07-14 12:04 AM Re: GetFileVersion not working right
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
At first blush, I see you are using file handle 1. Maybe it is already in use. you should never hard code the file handle in a UDF. You may want to look at using the FreeFileHandle() function. Doublecheck what $ScriptDir is set too as well.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#122822 - 2004-07-14 12:11 AM Re: GetFileVersion not working right
FieR0 Offline
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
#122823 - 2004-07-14 12:14 AM Re: GetFileVersion not working right
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
looks like you may need to ExpandEnvironmentVars().
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#122824 - 2004-07-14 06:56 AM Re: GetFileVersion not working right
FieR0 Offline
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
#122825 - 2004-07-14 08:35 AM Re: GetFileVersion not working right
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
your script is little bloated to really see where is the problem.
can't you show shorter example where it's not working as expected?
_________________________
!

download KiXnet

Top
#122826 - 2004-07-14 11:26 PM Re: GetFileVersion not working right
FieR0 Offline
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
#122827 - 2004-07-14 11:36 PM Re: GetFileVersion not working right
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Since you don't really say where you tried adding ExpandEnvironmentVars(), I still cannot rule it out.

Try replacing the line:
$line = ReadLine($arrayfilehandle)

with:
$line = ExpandEnvironmentVars(ReadLine($arrayfilehandle))
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#122828 - 2004-07-14 11:58 PM Re: GetFileVersion not working right
FieR0 Offline
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
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 885 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.056 seconds in which 0.022 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org