Information from the VERSIONINFO in EXE files (Windows)

574 views
Skip to first unread message

Juank

unread,
Sep 20, 2024, 12:04:49 PM9/20/24
to Harbour Users
Hi everyone !

Does anyone know how to retrieve information from the VERSIONINFO resource in EXE files (Windows) ?

Thank you in advance

JuanK

To set VERSIONINFO in EXE files (Windows) :

HBQuerier

unread,
Sep 20, 2024, 2:25:18 PM9/20/24
to Harbour Users
Haven't teseted it, but from  the OpenAI o1 Preview (I'll follow this email with a Claude Sonnet version):
#include "hbwin.ch" PROCEDURE Main() LOCAL cFileName := "C:\\Windows\\Notepad.exe" // Path to the executable LOCAL dwHandle := 0 LOCAL dwSize := GetFileVersionInfoSize(cFileName, @dwHandle) IF dwSize == 0 Alert("Failed to get version info size.") RETURN ENDIF LOCAL lpData := hb_xgrab(dwSize) // Allocate memory for version info IF .NOT. GetFileVersionInfo(cFileName, 0, dwSize, lpData) Alert("Failed to get version info.") hb_xfree(lpData) RETURN ENDIF LOCAL lpBuffer := 0 LOCAL uLen := 0 LOCAL cSubBlock := "\\StringFileInfo\\040904E4\\FileVersion" // Language and code page IF VerQueryValue(lpData, cSubBlock, @lpBuffer, @uLen) LOCAL cVersion := hb_PtrToStr(lpBuffer, uLen - 1) // Convert pointer to string Alert("File Version: " + cVersion) ELSE Alert("Failed to query version value.") ENDIF hb_xfree(lpData) // Free allocated memory RETURN FUNCTION GetFileVersionInfoSize(cFileName, @lpdwHandle) RETURN hb_DllCall("Version.dll", HB_DLL_STDCALL, "GetFileVersionInfoSizeA", cFileName, @lpdwHandle) ENDFUNC FUNCTION GetFileVersionInfo(cFileName, dwHandle, dwLen, lpData) RETURN hb_DllCall("Version.dll", HB_DLL_STDCALL, "GetFileVersionInfoA", cFileName, dwHandle, dwLen, lpData) ENDFUNC FUNCTION VerQueryValue(lpBlock, lpSubBlock, @lplpBuffer, @puLen) RETURN hb_DllCall("Version.dll", HB_DLL_STDCALL, "VerQueryValueA", lpBlock, lpSubBlock, @lplpBuffer, @puLen) ENDFUNC



HBQuerier

unread,
Sep 20, 2024, 2:26:17 PM9/20/24
to Harbour Users
Claude Sonnet 3.5:

#include "hbwin.ch"
#include "fileio.ch"

PROCEDURE Main()
    LOCAL cFileName := "C:\Windows\System32\kernel32.dll"
    LOCAL nInfoSize, pInfo, cInfo
    LOCAL nTranslate, pTranslate
    LOCAL cSubBlock, pValue, nValueLen
    LOCAL cCompanyName, cFileDescription, cFileVersion, cProductName, cProductVersion

    // Get the size of the version information
    nInfoSize := GetFileVersionInfoSize(cFileName, 0)
   
    IF nInfoSize == 0
        ? "Failed to get version info size."
        RETURN
    ENDIF

    // Allocate memory for the version information
    pInfo := hb_xgrab(nInfoSize)

    // Get the version information
    IF !GetFileVersionInfo(cFileName, 0, nInfoSize, pInfo)
        ? "Failed to get version info."
        hb_xfree(pInfo)
        RETURN
    ENDIF

    // Get the translation info
    IF !VerQueryValue(pInfo, "\VarFileInfo\Translation", @pTranslate, @nTranslate)
        ? "Failed to get translation info."
        hb_xfree(pInfo)
        RETURN
    ENDIF

    // Create the sub block string based on the language and code page
    cSubBlock := "\StringFileInfo\" + ;
                 hb_NumToHex(hb_BPeek(pTranslate, 1), 4) + ;
                 hb_NumToHex(hb_BPeek(pTranslate, 3), 4) + "\"

    // Retrieve various version information strings
    cCompanyName := GetVersionString(pInfo, cSubBlock + "CompanyName")
    cFileDescription := GetVersionString(pInfo, cSubBlock + "FileDescription")
    cFileVersion := GetVersionString(pInfo, cSubBlock + "FileVersion")
    cProductName := GetVersionString(pInfo, cSubBlock + "ProductName")
    cProductVersion := GetVersionString(pInfo, cSubBlock + "ProductVersion")

    // Display the retrieved information
    ? "Company Name:", cCompanyName
    ? "File Description:", cFileDescription
    ? "File Version:", cFileVersion
    ? "Product Name:", cProductName
    ? "Product Version:", cProductVersion

    // Free the allocated memory
    hb_xfree(pInfo)

RETURN

FUNCTION GetVersionString(pInfo, cSubBlock)
    LOCAL pValue, nValueLen, cValue := ""

    IF VerQueryValue(pInfo, cSubBlock, @pValue, @nValueLen)
        cValue := hb_BSubStr(pValue, 1, nValueLen - 1)
    ENDIF

RETURN cValue


On Friday, September 20, 2024 at 12:04:49 PM UTC-4 Juank wrote:

Juank

unread,
Sep 23, 2024, 8:10:20 AM9/23/24
to Harbour Users
Thank you so much HBQuerier
JuanK

Jayadev U

unread,
Sep 23, 2024, 10:36:23 AM9/23/24
to harbou...@googlegroups.com

Hi,

 

Got the following errors when compiling the code:

 

hbmk2: Error: Referenced, missing, but unknown function(s):

       GETFILEVERSIONINFOSIZE(), HB_XGRAB(), GETFILEVERSIONINFO(), HB_XFREE(),

       VERQUERYVALUE()

Could you please check.

 

Wbr,

 

Jayadev

--
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: https://groups.google.com/group/harbour-users
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/0a3a1114-73f7-43c6-84f5-f2db39824a63n%40googlegroups.com.

Francesco Perillo

unread,
Sep 23, 2024, 10:50:39 AM9/23/24
to harbou...@googlegroups.com
Please stop using IA to generate code !

HB_XGRAB and HB_XFREE are c functions not available in Clipper language !

The other win32 function calls are not even present in harbour source code, neither in contribs.

So, is it possible to have the informations from the .exe ? Yes, using something similar to that code but it should be written in C.




HBQuerier

unread,
Sep 23, 2024, 3:20:42 PM9/23/24
to Harbour Users
So?  I use AI all the time.  Some of the AIs generate solid code most of the time, but I often have to modify.  Everyone goes through this.

They help, even if they make mistakes sometimes.

I'll continue using them, as they evolve and become even more capable.

HBQuerier

unread,
Sep 23, 2024, 9:22:35 PM9/23/24
to Harbour Users
Juank,

Do you need this in Harbour?  Let me know, I can try and implement it in a Windows Hosting environment tomorrow,  jscript or vbscript. 

On Friday, September 20, 2024 at 12:04:49 PM UTC-4 Juank wrote:

Francesco Perillo

unread,
Sep 24, 2024, 2:46:21 AM9/24/24
to harbou...@googlegroups.com
You can do whatever you want, of course :-)

Harbour Users

unread,
Sep 24, 2024, 10:52:23 AM9/24/24
to Harbour Users
On Monday 23 September 2024 at 17:50:39 UTC+3 fperillo wrote:
Please stop using IA to generate code !


I have a short story to narrate, about using AI models and what to expect by them,
but I'm not sure whether it's OK to share it here, although it'd fit quite perfectly 
with the subject of thread . May I post it?  I still wonder.. :-)

regards,
Pete

Harbour Users

unread,
Sep 24, 2024, 11:13:13 AM9/24/24
to Harbour Users
Hello,
Attached , two functions to retrieve various file properties, 
probably more than what are included in VERSIONINFO resource.
Hope it'd be useful.

regards,
Pete
fileInfoFuncs.7z

HBQuerier

unread,
Sep 24, 2024, 12:42:38 PM9/24/24
to Harbour Users
You might have a point, about not sharing AI solutions untested, because it wastes people's time.  I'll go with that, and only post solutions that I've modified and tested successfully. 

By all means, share your thoughts Pete.  The evolution of AIs are in flux right now.  So almost anything we say might not apply a year from now, or ten years. 

Daniele Campagna

unread,
Sep 25, 2024, 5:24:41 AM9/25/24
to harbou...@googlegroups.com

Agreed. Plus, he has enticed us a bit! ;-)

Dan

Francesco Perillo

unread,
Sep 25, 2024, 11:47:39 AM9/25/24
to harbou...@googlegroups.com
I live in a building with several apartments. We have a "open-space" garage, the kind you find in shopping malls. As a private parking garage we need to obey some specific rules about fire prevention.

One people was given a Tesla as a work issued car so he needs a charger. He asked chatgpt and reported the answer in a meeting. Since I own a plugin (EV + ICE) I investigated the matter and I know chatgpt answer was wrong for our specific case.

When I told him that the answer was wrong for reason X Y and Z, he asked chatgpt again and now the answer is more appropriate but, I think still incomplete. We are talking about the system to disconnect power from outlets present in the parking in case fire-fighters must use pressurized water and not create short-circuits that can harm (or kill!!!) them.

So, no, chatgpt is not ready to be used as a search engine. And should never be trusted.

Message has been deleted

HBQuerier

unread,
Sep 25, 2024, 3:57:39 PM9/25/24
to Harbour Users
The key word here is 'never' be trusted.  In general, this is going to be unpredictable, at what point they can be trusted.  

I believe it's inevitable that some of the AIs will be more trustworthy and smarter than humans, but not ChatGPT or anything from OpenAI - the former director of the NSA is on the board, and they do not have our best interests at heart.  They made some great strides recently, but I personally am trying to avoid using any of their tools.

We'll be moving past LLMs, and there will be all sorts of surprises and revelations.  When the AIs become smart enough to design alternative economies or brainstorm new physics theories or solve the problem of aging, they will also present the proofs of their claims in a way that humans can verify.

It's true that there are limitations right now, and we have to build our own verifications.  But all of this is temporary.


**************************
I started an argument map called "The Threat of AIs", a couple of months ago.  It's not going to cover every position, but it will be a sort of survey of speculations.  Nobody knows what's going to happen.  Dystopia or near-Utopia ; no idea.  But they WILL be smarter and more reliable than humans in most or all fields.

There's a lot more to write on this map.  But I've interrupted all progress on the argument maps until more convenient tools can be built for generating them.  But for now, you can find "The Threat of AIs" at



Some of the other maps can be found on my Medium page, at https://dcwhatthe.medium.com/


The_Threat_of_AIs_Snippet.jpg
Reply all
Reply to author
Forward
0 new messages