Subscribe

RSS Feed (xml)

Retrieve Version Information for File

The .NET Framework allows you to retrieve file information without resorting to the Windows API. Instead, you simply need to use the FileVersionInfo class and call the GetVersionInfo method with the file name as a parameter. You can then retrieve extensive information through the FileVersionInfo properties.

The FileVersionInfo properties are too numerous to list here, but the following code snippet shows an example of what you might retrieve:

using System;
using System.Diagnostics;

public class VersionInfo {

    private static void Main(string[] args) {

        if (args.Length == 0) {

            Console.WriteLine("Please supply a  file name.");
            return;
        }

        FileVersionInfo info = FileVersionInfo.GetVersionInfo(args[0]);

        // Display version information.
        Console.WriteLine("Checking File: " + info. file name);
        Console.WriteLine("Product Name: " + info.ProductName);
        Console.WriteLine("Product Version: " + info.ProductVersion);
        Console.WriteLine("Company Name: " + info.CompanyName);
        Console.WriteLine("File Version: " + info.FileVersion);
        Console.WriteLine("File Description: " + info.FileDescription);
        Console.WriteLine("Original  file name: " + info.Original file name);
        Console.WriteLine("Legal Copyright: " + info.LegalCopyright);
        Console.WriteLine("InternalName: " + info.InternalName);
        Console.WriteLine("IsDebug: " + info.IsDebug);
        Console.WriteLine("IsPatched: " + info.IsPatched);
        Console.WriteLine("IsPreRelease: " + info.IsPreRelease);
        Console.WriteLine("IsPrivateBuild: " + info.IsPrivateBuild);
        Console.WriteLine("IsSpecialBuild: " + info.IsSpecialBuild);
        
        Console.ReadLine();
    }
}

Here's the output this code produces if you run the command VersionInfo c:\windows\explorer.exe:

Checking File: c:\windows\explorer.exe
Product Name: Microsoftr Windowsr Operating System
Product Version: 6.00.2600.0000
Company Name: Microsoft Corporation
File Version: 6.00.2600.0000 (xpclient.010817-1148)
File Description: Windows Explorer
Original  file name: EXPLORER.EXE
Legal Copyright: c Microsoft Corporation. All rights reserved.
InternalName: explorer
IsDebug: False
IsPatched: False
IsPreRelease: False
IsPrivateBuild: False
IsSpecialBuild: False

Technorati :

No comments:

Post a Comment

Archives

LocalsAdda.com-Variety In Web World

Fun Mail - Fun in the Mail