Newsgroup: it.comp.lang.visual-basic
Titolo: Informazioni file exe

Ciao sto pensando di fare un programmino di aggiornamento.
Avrei necessità di avere le inofrmazioni sul file exe che devo sostuire, 
come la versione.
Ho visto che quando compilo la verisone del exe aumenta progressivamente e 
che con il tasto destro mi restituisce nelle proprietà la versione del file.
C'è un modo per reperire queste informazioni?
Ancora, c'è un modo per chiudere un processo.. appunto per aggiornare il 
file exe che risulterebbe impegnato?
Grazie 


Ho trovato questi esempi per prendere il Version ovviamente non sono
testati:
Esempio 1:
Private Declare Function GetFileVersionInfoSize Lib "version.dll"
Alias _
    "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, _
    lpdwHandle As Long) As Long
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
' Get versioning information about a file
' it only works with Win32 files, and under Windows 95/98 the short
path
' form of the specified file name must be less than 126 characters.
'
' If unsuccessful returns Empty
' If successful returns an array of strings in the format
'        "resourcename: resourcevalue"
' if a resource value hasn't been found, the string contains
' just the resource name, and you can filter out these items
' using the following statement
'      resources() = Filter(GetFileVersionData(FileName), ":")
'
' Usage:
'     Dim res As Variant, i As Long
'     res = GetFileVersionData(FileName)
'     If IsArray(res) Then
'         For i = LBound(res) To UBound(res)
'             Debug.Print res(i)
'         Next
'     End If
Function GetFileVersionData(ByVal FileName As String) As Variant
    Dim length As Long
    Dim handle As Long
    Dim buffer As String
    Dim index As Long
    Dim pos As Long
    ' get the size of the version info block
    ' (handle is always set to zero by the function
    length = GetFileVersionInfoSize(FileName, handle)
    If length = 0 Then Exit Function
    ' create the buffer (these are Unicode chars)
    buffer = Space$(length)
    ' get version information (2nd argument is ignored)
    If GetFileVersionInfo(FileName, handle, length, ByVal
StrPtr(buffer)) = 0 _
        Then
    ' a zero return value means error
    Exit Function
End If
' extract version information out of the buffer
' IMPORTANT: it doesn't use the official APIs, instead
' it uses euristics to extract the strings, and might
' fail under some circumstances
' create an array with the names of all the standard resources
Dim res() As String
res() = Split("CompanyName;FileDescription;FileVersion;InternalName;"
& _
    "LegalCopyright;OriginalFilename;ProductName;ProductVersion;" & _
    "Comments;LegalTrademarks;PrivateBuild;SpecialBuild", ";")
' repeat for all the standard resources
For index = 0 To UBound(res)
    pos = InStr(buffer, res(index))
    If pos Then
        ' skip over the resource name
        pos = pos + Len(res(index)) + 1
        ' if this is a null char, skip over it
        If Mid$(buffer, pos, 1) = vbNullChar Then pos = pos + 1
        ' extract the null terminated string and
        ' append it to the resource name
        res(index) = res(index) & ": " & Mid$(buffer, pos, InStr(pos,
_
            buffer, vbNullChar) - pos)
    End If
Next
GetFileVersionData = res()
End Function
Esempio 2:
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 Function lstrcpy Lib "kernel32" Alias
"lstrcpyA" (lpString1 As Any, lpString2 As Any) As Long
Private Sub Command1_Click()
    Dim sVerInfo(7) As String
    Dim sInfo As String
    Dim sValue As String
    Dim sFile As String
    Dim sData() As Byte
    Dim lSize As Long
    Dim lPointer As Long
    Dim iIndex As Integer
    On Error GoTo OpenError
    With CommonDialog1
        .CancelError = True
        .ShowOpen
        sFile = .FileName
    End With
    Text1 = ""
    'get the Length of the FileVersion Information
    lSize = GetFileVersionInfoSize(sFile, ByVal 0&)
    'Create a Buffer to hold the Version Info
    ReDim sData(lSize)
    'get the Version Info
    If GetFileVersionInfo(sFile, 0&, lSize, sData(0)) Then
        'Extract the Details of the Version Info
        sVerInfo(0) = "CompanyName"
        sVerInfo(1) = "FileDescription"
        sVerInfo(2) = "FileVersion"
        sVerInfo(3) = "InternalName"
        sVerInfo(4) = "LegalCopyright"
        sVerInfo(5) = "OriginalFileName"
        sVerInfo(6) = "ProductName"
        sVerInfo(7) = "ProductVersion"
        For iIndex = 0 To 7
            sInfo = "\StringFileInfo\040904E4\" & sVerInfo(iIndex)
            If VerQueryValue(sData(0), sInfo, lPointer, lSize) Then
                sValue = Space(lSize)
                lstrcpy ByVal sValue, ByVal lPointer
                Text1.SelText = sVerInfo(iIndex) & ": " & sValue
                Text1.SelText = vbCrLf
            End If
        Next
    End If
    OpenError:
End Sub

 ha scritto nel messaggio 
news:H5rLh.28174

Se in .Net tutte le info le trovi con la classe Assembly (e forse c'è 
qualcosa anche nella System.IO)
Ciao