Solved

how to check existing program installed?

Posted on 2002-04-15
18
160 Views
Last Modified: 2010-05-02
I have to create an application called updatingFiles.exe for users to install the updated files.
There are few programs called test1.exe and test2.exe installed in their pc.
About every mth, there will be other updated setup.exe files sent by other vendors and residing in our network.
They will have to install it to their pc every mth or so.

Question.
How would i check whether the updated setup.exe files sent by the vendors are newer in
version than their? REMEMBER: They are to click the updatingFiles.exe every now and then
to check whether any newer versions of the files is being uploaded to the network.
URGENT!!!!
0
Comment
Question by:laukhengsiong
18 Comments
 
LVL 1

Accepted Solution

by:
ProgramIT earned 5 total points
ID: 6943990
The easiest way would be to use the GetFileVersionEX API call.

Example:
Const VS_FFI_SIGNATURE = &HFEEF04BD
Const VS_FFI_STRUCVERSION = &H10000
Const VS_FFI_FILEFLAGSMASK = &H3F&
Const VS_FF_DEBUG = &H1
Const VS_FF_PRERELEASE = &H2
Const VS_FF_PATCHED = &H4
Const VS_FF_PRIVATEBUILD = &H8
Const VS_FF_INFOINFERRED = &H10
Const VS_FF_SPECIALBUILD = &H20
Const VOS_UNKNOWN = &H0
Const VOS_DOS = &H10000
Const VOS_OS216 = &H20000
Const VOS_OS232 = &H30000
Const VOS_NT = &H40000
Const VOS__BASE = &H0
Const VOS__WINDOWS16 = &H1
Const VOS__PM16 = &H2
Const VOS__PM32 = &H3
Const VOS__WINDOWS32 = &H4
Const VOS_DOS_WINDOWS16 = &H10001
Const VOS_DOS_WINDOWS32 = &H10004
Const VOS_OS216_PM16 = &H20002
Const VOS_OS232_PM32 = &H30003
Const VOS_NT_WINDOWS32 = &H40004
Const VFT_UNKNOWN = &H0
Const VFT_APP = &H1
Const VFT_DLL = &H2
Const VFT_DRV = &H3
Const VFT_FONT = &H4
Const VFT_VXD = &H5
Const VFT_STATIC_LIB = &H7
Const VFT2_UNKNOWN = &H0
Const VFT2_DRV_PRINTER = &H1
Const VFT2_DRV_KEYBOARD = &H2
Const VFT2_DRV_LANGUAGE = &H3
Const VFT2_DRV_DISPLAY = &H4
Const VFT2_DRV_MOUSE = &H5
Const VFT2_DRV_NETWORK = &H6
Const VFT2_DRV_SYSTEM = &H7
Const VFT2_DRV_INSTALLABLE = &H8
Const VFT2_DRV_SOUND = &H9
Const VFT2_DRV_COMM = &HA
Private Type VS_FIXEDFILEINFO
   dwSignature As Long
   dwStrucVersionl As Integer     '  e.g. = &h0000 = 0
   dwStrucVersionh As Integer     '  e.g. = &h0042 = .42
   dwFileVersionMSl As Integer    '  e.g. = &h0003 = 3
   dwFileVersionMSh As Integer    '  e.g. = &h0075 = .75
   dwFileVersionLSl As Integer    '  e.g. = &h0000 = 0
   dwFileVersionLSh As Integer    '  e.g. = &h0031 = .31
   dwProductVersionMSl As Integer '  e.g. = &h0003 = 3
   dwProductVersionMSh As Integer '  e.g. = &h0010 = .1
   dwProductVersionLSl As Integer '  e.g. = &h0000 = 0
   dwProductVersionLSh As Integer '  e.g. = &h0031 = .31
   dwFileFlagsMask As Long        '  = &h3F for version "0.42"
   dwFileFlags As Long            '  e.g. VFF_DEBUG Or VFF_PRERELEASE
   dwFileOS As Long               '  e.g. VOS_DOS_WINDOWS16
   dwFileType As Long             '  e.g. VFT_DRIVER
   dwFileSubtype As Long          '  e.g. VFT2_DRV_KEYBOARD
   dwFileDateMS As Long           '  e.g. 0
   dwFileDateLS As Long           '  e.g. 0
End Type
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
Private Declare Function VerQueryValue Lib "Version.dll" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Any, puLen As Long) As Long
Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, ByVal Source As Long, ByVal length As Long)
Dim Filename As String, Directory As String, FullFileName As String
Dim StrucVer As String, FileVer As String, ProdVer As String
Dim FileFlags As String, FileOS As String, FileType As String, FileSubType As String
Private Sub DisplayVerInfo()
   Dim rc As Long, lDummy As Long, sBuffer() As Byte
   Dim lBufferLen As Long, lVerPointer As Long, udtVerBuffer As VS_FIXEDFILEINFO
   Dim lVerbufferLen As Long

   '*** Get size ****
   lBufferLen = GetFileVersionInfoSize(FullFileName, lDummy)
   If lBufferLen < 1 Then
      MsgBox "No Version Info available!"
      Exit Sub
   End If

   '**** Store info to udtVerBuffer struct ****
   ReDim sBuffer(lBufferLen)
   rc = GetFileVersionInfo(FullFileName, 0&, lBufferLen, sBuffer(0))
   rc = VerQueryValue(sBuffer(0), "\", lVerPointer, lVerbufferLen)
   MoveMemory udtVerBuffer, lVerPointer, Len(udtVerBuffer)

   '**** Determine Structure Version number - NOT USED ****
   StrucVer = Format$(udtVerBuffer.dwStrucVersionh) & "." & Format$(udtVerBuffer.dwStrucVersionl)

   '**** Determine File Version number ****
   FileVer = Format$(udtVerBuffer.dwFileVersionMSh) & "." & Format$(udtVerBuffer.dwFileVersionMSl) & "." & Format$(udtVerBuffer.dwFileVersionLSh) & "." & Format$(udtVerBuffer.dwFileVersionLSl)

   '**** Determine Product Version number ****
   ProdVer = Format$(udtVerBuffer.dwProductVersionMSh) & "." & Format$(udtVerBuffer.dwProductVersionMSl) & "." & Format$(udtVerBuffer.dwProductVersionLSh) & "." & Format$(udtVerBuffer.dwProductVersionLSl)

   '**** Determine Boolean attributes of File ****
   FileFlags = ""
   If udtVerBuffer.dwFileFlags And VS_FF_DEBUG Then FileFlags = "Debug "
   If udtVerBuffer.dwFileFlags And VS_FF_PRERELEASE Then FileFlags = FileFlags & "PreRel "
   If udtVerBuffer.dwFileFlags And VS_FF_PATCHED Then FileFlags = FileFlags & "Patched "
   If udtVerBuffer.dwFileFlags And VS_FF_PRIVATEBUILD Then FileFlags = FileFlags & "Private "
   If udtVerBuffer.dwFileFlags And VS_FF_INFOINFERRE Then FileFlags = FileFlags & "Info "
   If udtVerBuffer.dwFileFlags And VS_FF_SPECIALBUILD Then FileFlags = FileFlags & "Special "
   If udtVerBuffer.dwFileFlags And VFT2_UNKNOWN Then FileFlags = FileFlags + "Unknown "

   '**** Determine OS for which file was designed ****
   Select Case udtVerBuffer.dwFileOS
      Case VOS_DOS_WINDOWS16
        FileOS = "DOS-Win16"
      Case VOS_DOS_WINDOWS32
        FileOS = "DOS-Win32"
      Case VOS_OS216_PM16
        FileOS = "OS/2-16 PM-16"
      Case VOS_OS232_PM32
        FileOS = "OS/2-16 PM-32"
      Case VOS_NT_WINDOWS32
        FileOS = "NT-Win32"
      Case other
        FileOS = "Unknown"
   End Select
   Select Case udtVerBuffer.dwFileType
      Case VFT_APP
         FileType = "App"
      Case VFT_DLL
         FileType = "DLL"
      Case VFT_DRV
         FileType = "Driver"
         Select Case udtVerBuffer.dwFileSubtype
            Case VFT2_DRV_PRINTER
               FileSubType = "Printer drv"
            Case VFT2_DRV_KEYBOARD
               FileSubType = "Keyboard drv"
            Case VFT2_DRV_LANGUAGE
               FileSubType = "Language drv"
            Case VFT2_DRV_DISPLAY
               FileSubType = "Display drv"
            Case VFT2_DRV_MOUSE
               FileSubType = "Mouse drv"
            Case VFT2_DRV_NETWORK
               FileSubType = "Network drv"
            Case VFT2_DRV_SYSTEM
               FileSubType = "System drv"
            Case VFT2_DRV_INSTALLABLE
               FileSubType = "Installable"
            Case VFT2_DRV_SOUND
               FileSubType = "Sound drv"
            Case VFT2_DRV_COMM
               FileSubType = "Comm drv"
            Case VFT2_UNKNOWN
               FileSubType = "Unknown"
         End Select
      Case VFT_FONT
         FileType = "Font"
         Select Case udtVerBuffer.dwFileSubtype
            Case VFT_FONT_RASTER
               FileSubType = "Raster Font"
            Case VFT_FONT_VECTOR
               FileSubType = "Vector Font"
            Case VFT_FONT_TRUETYPE
               FileSubType = "TrueType Font"
         End Select
      Case VFT_VXD
         FileType = "VxD"
      Case VFT_STATIC_LIB
         FileType = "Lib"
      Case Else
         FileType = "Unknown"
   End Select
End Sub
Private Sub Form_Load()
    'KPD-Team 2000
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    'Source -> MS Knowledge Base
    'set the file
    Filename = "kernel32.dll"
    Directory = "c:\windows\system\"
    FullFileName = Directory + Filename
    'set graphics mode to persistent
    Me.AutoRedraw = True
    'retrieve the information
    DisplayVerInfo
    'show the results
    Me.Print "Full filename: " + FullFileName
    Me.Print "File version: " + FileVer
    Me.Print "Produkt version: " + ProdVer
    Me.Print "File flags: " + FileFlags
    Me.Print "File OS: " + FileOS
    Me.Print "File type: " + FileType + IIf(FileSubType = "", "", " (" + FileSubType + ")")
End Sub

0
 
LVL 1

Expert Comment

by:olx
ID: 6946005
i have a doubt:
every time you need to copy only the new file or setup again the app?

0
 
LVL 1

Expert Comment

by:olx
ID: 6946025

if you need to update only the new files do this:

Sub main()

    'chech if the app is running
    Do
        On Error Resume Next
        AppActivate "appname"
        If Err = 0 Then
            MsgBox "be sure to close the app before continuing...", vbCritical, ""
        Else
            Exit Do
        End If
        Err.Clear
    Loop
   
    'q is the server drive where the updated files are
   
    update "c:\program files\app\prog1.exe", "q:\updates\progr1.exe"
    update "c:\program files\app\prog2.exe", "q:\updates\progr2.exe"
    update "c:\program files\app\prog3.dat", "q:\updates\progr3.dat"
    update "c:\program files\app\prog4.dll", "q:\updates\progr4.dll"
    update "c:\program files\app\stuff.bmp", "q:\updates\stuff5.bmp"
   
    'finaly run the app
   
    Shell "c:\program files\app\main.exe", vbNormalFocus
   
    End
   
End Sub

Sub update(source As String, target As String)
   
    If FileDateTime(source) < FileDateTime(target) Then FileCopy source, target

End Sub

make it an exe.
tell your users to use it instead their current app icon.

hope this helps


0
 
LVL 1

Expert Comment

by:olx
ID: 6946049
sorry
the sign is backwards.
   
sub update(source As String, target As String)
   
   If FileDateTime(source) > FileDateTime(target) Then FileCopy source, target

End Sub
;)

i constantly need this kind of updates with local apps we developed.
0
 

Author Comment

by:laukhengsiong
ID: 6946675
Ok ProgramIT ur program works fine BUT:
When i install one of older version of the setupfiles, it will automatically create an exe program. let's call it Winquote.exe. After that, i check the new version of the setup.exe file and found that the version between these two are DIFFERENT. The winquote.exe is version 2.00.1 while the new version of the setup.exe file is 1.00.01.
How come the setup.exe version is NOT latest than the winquote.exe????
0
 

Author Comment

by:laukhengsiong
ID: 6946703
Ok ProgramIT ur program works fine BUT:
When i install one of older version of the setupfiles, it will automatically create an exe program. let's call it Winquote.exe. After that, i check the new version of the setup.exe file and found that the version between these two are DIFFERENT. The winquote.exe is version 2.00.1 while the new version of the setup.exe file is 1.00.01.
How come the setup.exe version is NOT latest than the winquote.exe????
0
 

Author Comment

by:laukhengsiong
ID: 6946728
Ok ProgramIT ur program works fine BUT:
When i install one of older version of the setupfiles, it will automatically create an exe program. let's call it Winquote.exe. After that, i check the new version of the setup.exe file and found that the version between these two are DIFFERENT. The winquote.exe is version 2.00.1 while the new version of the setup.exe file is 1.00.01.
How come the setup.exe version is NOT latest than the winquote.exe????
0
 

Author Comment

by:laukhengsiong
ID: 6946780
Ok ProgramIT ur program works fine BUT:
When i install one of older version of the setupfiles, it will automatically create an exe program. let's call it Winquote.exe. After that, i check the new version of the setup.exe file and found that the version between these two are DIFFERENT. The winquote.exe is version 2.00.1 while the new version of the setup.exe file is 1.00.01.
How come the setup.exe version is NOT latest than the winquote.exe????
0
 

Author Comment

by:laukhengsiong
ID: 6946795
Ok ProgramIT ur program works fine BUT:
When i install one of older version of the setupfiles, it will automatically create an exe program. let's call it Winquote.exe. After that, i check the new version of the setup.exe file and found that the version between these two are DIFFERENT. The winquote.exe is version 2.00.1 while the new version of the setup.exe file is 1.00.01.
How come the setup.exe version is NOT latest than the winquote.exe????
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:laukhengsiong
ID: 6946814
Ok ProgramIT ur program works fine BUT:
When i install one of older version of the setupfiles, it will automatically create an exe program. let's call it Winquote.exe. After that, i check the new version of the setup.exe file and found that the version between these two are DIFFERENT. The winquote.exe is version 2.00.1 while the new version of the setup.exe file is 1.00.01.
How come the setup.exe version is NOT latest than the winquote.exe????
0
 

Author Comment

by:laukhengsiong
ID: 6946898
Ok ProgramIT ur program works fine BUT:
When i install one of older version of the setupfiles, it will automatically create an exe program. let's call it Winquote.exe. After that, i check the new version of the setup.exe file and found that the version between these two are DIFFERENT. The winquote.exe is version 2.00.1 while the new version of the setup.exe file is 1.00.01.
How come the setup.exe version is NOT latest than the winquote.exe????
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 6952206
laukhenqsionq - you should hit the reload question button at the top rather than refresh button.
0
 

Author Comment

by:laukhengsiong
ID: 6958776
Thank ProgramIT... The solution u gave me does not help much. It is because the version of the setup.exe files given by other companies are not updated so the GetFileVersion function is not valid. I found out when i click on the properties of the setup.exe files. Anyway thanks
0
 

Author Comment

by:laukhengsiong
ID: 6958783
Does anyone know whether window scripting host will help???
0
 
LVL 1

Expert Comment

by:olx
ID: 6960380
laukhengsiong

the file dates get changed?
0
 
LVL 1

Expert Comment

by:olx
ID: 6960536
laukhengsiong

the file dates get changed?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7654103
Hi laukhengsiong,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept ProgramIT's comment(s) as an answer.

laukhengsiong, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 7755095
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now