Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Version from Non Executing Executable File

Tags:

c#

I know how to get the version of an executing application or dll. However I need to find the properties of a non executing application.

I have a small program to set a file association for my main application. There is no point in users of old versions running this since the application does not accept arguments on start up. So when the file associator starts it first checks to see if it can find the main app. If it can then I want to check the properties without executing it. If the version is earlier than one that can accept arguments then I want to tell my user to update rather than proceed to set the association.

I have looked at System.IO.FileInfo but that does not seem to include any Version information.

Thanks

like image 911
ScruffyDuck Avatar asked May 11 '11 10:05

ScruffyDuck


People also ask

How do I find the version of an EXE file?

For example, Oracle Java has the java.exe file, CCleaner has ccleaner.exe and so on. Right click on it and then select Properties. In the Properties window, go to the Details tab. There you will find information about the product name, the product version and so on.

How do I change the version number of an EXE file?

For a file that is missing version info completely: After opening the DLL in Visual Studio, go to Edit > Add Resource > Version and click New. Then in the new Version tab, change FILEVERSION and PRODUCTVERSION, CompanyName, etc. Save the files and you're all set!

Can I get code from EXE file?

A .exe is a binary code, unless its instrumented with source code for debugging its close to impossible to get the source code.


1 Answers

You can use FileVersionInfo.GetVersionInfo():

FileVersionInfo vi = FileVersionInfo.GetVersionInfo("myfile.dll");

string showVersion = vi.FileVersion;

//showVersion is the actual version No.

This returns file/document metadata and can be used for unmanaged DLLs or even word documents as well.

You can also use Assembly:

Version v = Assembly.ReflectionOnlyLoadFrom("myfile.dll").GetName().Version;

This will contain .NET version information.

like image 138
Aliostad Avatar answered Nov 15 '22 00:11

Aliostad