OdeToCode IC Logo

FileVesionInfo

Tuesday, July 27, 2004
Getting the version number of any managed / unmanaged DLL or executable in .NET 1.0, if I recall correctly, required some magic incantations with PInvoke.

I just discovered the FileVersionInfo class from System.Diagnostics:

FileVersionInfo versionInfo;
versionInfo = FileVersionInfo.GetVersionInfo(@"e:\win2003\system32\svchost.exe");
MessageBox.Show(versionInfo.ToString());

Notice the class overrides the ToString method to provide nicely formatted information:

File:             e:\win2003\system32\svchost.exe
InternalName:     svchost.exe
OriginalFilename: svchost.exe
FileVersion:      5.2.3790.0 (srv03_rtm.030324-2048)
FileDescription:  Generic Host Process for Win32 Services
Product:          Microsoft® Windows® Operating System
ProductVersion:   5.2.3790.0
Debug:            False
Patched:          False
PreRelease:       False
PrivateBuild:     False
SpecialBuild:     False
Language          English (United States)