Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi.I have a .exe file that created by Borlandc,and know i want to read the version of this file by C#.i have 2 questions:
1)how to read .exe file?
2)how to search in content of .exe file and find the some detail for example "version:[3.2.6]" ?
please help me. thanks so much.

What I have tried:

i can not find any solution for my question.please help me.
Posted
Updated 23-Jan-20 9:43am

You are assuming that the version number will exist as a string, and that's quite possibly not going to even exist - particularly in C, there are no "hard and fast" rules for how to handle version numbers. Unlike C# where it's a part of the assembly, in C it's a lot more free form, and any version numbering system is totally up to the developer.

So you might find C code that goes:
C++
printf("Version: [%u.%u.%u]", vMajor, vMinor, vRev);
Or it could be
C++
printf("Version: [3.2.6]");
Or even
C++
printf("Version: %s", revisuionInformation);
And it doesn't even have to be the same from version to version!
It's even possible that the text "Version" is held in a table of different language words for globalisation purposes, and the code that uses it is thousands of lines of code away!

So "hunting" though an EXE looking for it is going to be a dodgy principal at best.

But ... read the EXE file into an array of bytes:
C#
byte[] file = File.readAllBytes(pathToExeFile);

And start searching for "Version" in a loop.
It's simple enough to do, but be aware that it's probably not going to give you anything particularly useful.
 
Share this answer
 
Comments
Member 14724878 23-Jan-20 15:13pm    
thanks so much.
yes. In my C code i used "#define version [4.2.3]".
and know i want to search "[4.2.3] string in my .exe file .
by using this code : byte[] file = File.readAllBytes(pathToExeFile);
i must search character by character? how to use it?
thanks so much for your answer.
OriginalGriff 24-Jan-20 2:06am    
"i must search character by character?"
Yes - there is no "standard function" to search a byte array for a string.
So convert the search string to a byte array, and start looking for it inside a loop.
Member 14724878 24-Jan-20 8:50am    
thanks so much;I want to make APP that set in Right click in windows7(OS).
When open My Computer and go to the main Directory and then select a folder and Right click,then show my APP in right Click,then open it and tell me the path of This folder.
how can i do it?in C#. Please give me a source code that can do this job.
OriginalGriff 24-Jan-20 10:02am    
"Please give me a source code that can do this job."
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Member 14724878 24-Jan-20 13:45pm    
that's right.thanks for your responsibility. i want to send my code.but there isn't any attach menu to send it for you.please send for me your email that i send for you my little APP.
It is not an easy task.

Start reading this VERSIONINFO resource - Win32 apps | Microsoft Docs[^]

The hard part for you will be, that this needs to be done in c# by using P/Invoke.

[Edit]
Looks like there is an easier way which works in c# also for native W32 exe: FileVersionInfo Class (System.Diagnostics) | Microsoft Docs[^]
 
Share this answer
 
v2
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900