-
November 18th, 1999, 07:56 AM
#1
Check file version ?
I am working on a program where it is necessary for me to distinguish from wich version of Microsoft Office a certain program file comes from. I am for example using a API to find all Winword.exe on the machine, this works great, but I may end up with 3 winword.exe. I am now unable to part these files from one another. I found a API that can detirmine the version of these program files, but unfortunatly it doesn't work on all versions. I need something to part these files from each other, if it is possible.
I have just started working with VB, so it would be kind of anyone who answers to make it easy to understand. )
-
November 18th, 1999, 10:39 AM
#2
Re: Check file version ?
you said you found an api for retrieving the version from an exe, but it didn't work on all exes.
This may be because some versions of winword.exe are 16 bit versions.
the 32 bit version apis only work for 32 bit modules, the 16 bit version apis only for 16 bit modules.
The only way to use them both in a 32 bit vb app is to write a 16 ole server (e.g. in the 16 bit version of vb 4) and call that from your 32 bit vb app.
use the 32-bit version apis in your 32 bit vb app and the 16 bit version apis in your 16 bit ole server.
-
November 18th, 1999, 10:53 AM
#3
Re: Check file version ?
Ok, thanks for the answer.
I am not sure that I with my knowledge in VB can do this, but I will sure look in to it. Do you or anyone else have any good idea how I can get around this problem. Is there a way to solve my problem without checking the version of the file.
I somehow have to find out wich Office versions are installed on a computer and then find the path to all their main programs.
-
November 18th, 1999, 01:40 PM
#4
Re: Check file version ?
Try this code I wrote a while ago, it should work for 16/32-bit Files..
Code:
private Declare Function GetFileVersionInfo Lib "version.dll" Alias "GetFileVersionInfoA" (byval lptstrFilename as string, byval dwHandle as Long, byval dwLen as Long, lpData as Any) as Long
private Declare Function GetFileVersionInfoSize Lib "version.dll" Alias "GetFileVersionInfoSizeA" (byval lptstrFilename as string, lpdwHandle as Long) as Long
public Function GetVersion(byval sFile as string) as string
Dim sVerInfo as string
Dim iVerLen as Integer
Dim iVerPos as Long
iVerLen = GetFileVersionInfoSize(sFile, 0&)
sVerInfo = Space(iVerLen)
Call GetFileVersionInfo(sFile, 0&, iVerLen, byval sVerInfo)
iVerPos = InStr(sVerInfo, "FileVersion") + 12
If iVerPos = 12 then
'No Version Info, Check for 32bit File -
'32Bit Files Return Unicode Strings
sVerInfo = StrConv(sVerInfo, vbFromUnicode)
iVerPos = InStr(sVerInfo, "FileVersion") + 13
End If
If iVerPos > 12 then GetVersion = GetVersion & mid(sVerInfo, iVerPos, InStr(iVerPos, sVerInfo, Chr(0)) - 1)
End Function
private Sub Command1_Click()
on error GoTo UserCancelled
With CommonDialog1
.DialogTitle = "Select a File.."
.CancelError = true
.Filter = "All Files|*.dll;*.exe"
.ShowOpen
Caption = GetVersion(.FileName)
End With
UserCancelled:
End Sub
Aaron Young
Analyst Programmer
adyoung@win.bright.net
aarony@redwingsoftware.com
Last edited by Cimperiali; July 23rd, 2004 at 05:31 PM.
Reason: Adding Code tags
-
November 19th, 1999, 02:26 AM
#5
Re: Check file version ?
Thank You very much.
It is working great !!
/Leyan
-
November 19th, 1999, 04:07 AM
#6
Re: Check file version ?
Ok, I was absolutely wrong.
Sorry for the confusion.
Aaron Youngs code is the right way to go.
-
November 19th, 1999, 10:55 AM
#7
Re: Check file version ?
I used the code I got from Aaron, and my application is working great, not a single bug......on my computer.....as soon as someone else uses my app they get a invalid procedure call on the line:
Code:
If iVerPos > 12 Then GetVersion = GetVersion & Mid(sVerInfo, iVerPos, InStr(iVerPos, sVerInfo, Chr(0)) - 1)
Do anyone have a clue why ?
/Leyan
Last edited by Cimperiali; July 23rd, 2004 at 05:32 PM.
Reason: subst > with >
-
November 19th, 1999, 12:33 PM
#8
Re: Check file version ?
I couldn't reproduce the Error here, but
It could be the Instr Function is Returning Zero, making the Mid Function Call Illeagal, try this at the End of the GetVersion Routine instead..
Code:
If iVerPos > 12 then
iVerLen = InStr(iVerPos, sVerInfo, Chr(0)) - 1
If iVerLen > 0 then GetVersion = GetVersion & mid(sVerInfo, iVerPos, iVerLen)
End If
If the file you checked on your PC was the Same one that Caused the Error on the Other, I don't know how that could happen.
Aaron Young
Analyst Programmer
adyoung@win.bright.net
aarony@redwingsoftware.com
Last edited by Cimperiali; July 23rd, 2004 at 05:33 PM.
Reason: Code tags and > to >
-
November 19th, 1999, 03:08 PM
#9
Re: Check file version ?
I tried this on my computer at home, and it worked with this change. I will try it on a couple of other machines on Monday when I get back to work, but I guess you solved it for me.
I am very greatful. Thank you.
(Some of the files I checked on the other computers were the same ones, that sure made me pusseled too. Maybe it is something in my code, because to be honest I haven't tried your code alone on other computers)
Leyan
-
July 23rd, 2004, 05:34 PM
#10
Something from the deep
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|