GetFileVersionData – Retrieve file versioning information

GetFileVersionData – Retrieve file versioning information

Private Declare Function GetFileVersionInfoSize Lib "version.dll" Alias _    "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, _    lpdwHandle As Long) As LongPrivate 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 IfFunction 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

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as