System.Diagnostics Namespac ...


.NET Framework Class Library
FileVersionInfo Class

Provides version information for a physical file on disk.

Namespace:  System.Diagnostics
Assembly:  System (in System.dll)
Syntax

Visual Basic (Declaration)
<PermissionSetAttribute(SecurityAction.LinkDemand, Name := "FullTrust")> _
Public NotInheritable Class FileVersionInfo
Visual Basic (Usage)
Dim instance As FileVersionInfo
C#
[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
public sealed class FileVersionInfo
Visual C++
[PermissionSetAttribute(SecurityAction::LinkDemand, Name = L"FullTrust")]
public ref class FileVersionInfo sealed
JScript
public final class FileVersionInfo
Remarks

Typically, a version number is displayed as "major number.minor number.build number.private part number". A file version number is a 64-bit number that holds the version number for a file as follows:

Use the GetVersionInfo method of this class to get a FileVersionInfo containing information about a file, then look at the properties for information about the file. The FileVersion property provides version information about the file. The ProductMajorPart, ProductMinorPart, ProductBuildPart, ProductPrivatePart, and ProductVersion properties provide version information for the product that the specified file is a part of. Call ToString to get a partial list of properties and their values for this file.

The FileVersionInfo properties are based on version resource information built into the file. Version resources are often built into binary files such as .exe or .dll files; text files do not have version resource information.

Version resources are typically specified in a Win32 resource file, or in assembly attributes. For example the IsDebug property reflects the VS_FF_DEBUG flag value in the file's VS_FIXEDFILEINFO block, which is built from the VERSIONINFO resource in a Win32 resource file. For more information about specifying version resources in a Win32 resource file, see "About Resource Files" and "VERSIONINFO Resource" in the Platform SDK. For more information about specifying version resources in a .NET module, see the Setting Assembly Attributes topic.

NoteNote:

This class makes a link demand at the class level that applies to all members. A SecurityException is thrown when the immediate caller does not have full trust permission. For details about link demands, see Link Demands.

Examples

The following example calls GetVersionInfo to get the FileVersionInfo for the Notepad. Then it prints the file description and version number in a text box. This code assumes textBox1 has been instantiated.

Visual Basic
    Public Shared Sub Main(ByVal args() As String)
        ' Get the file version for the notepad.
        FileVersionInfo.GetVersionInfo(Path.Combine(Environment.SystemDirectory, "Notepad.exe"))
        Dim myFileVersionInfo As FileVersionInfo = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory + "\Notepad.exe")


        ' Print the file name and version number.
        Console.WriteLine("File: " + myFileVersionInfo.FileDescription + vbLf + "Version number: " + myFileVersionInfo.FileVersion)

    End Sub
End Class

C#
    public static void Main(string[] args)
    {
        // Get the file version for the notepad.
        FileVersionInfo.GetVersionInfo(Path.Combine(Environment.SystemDirectory, "Notepad.exe"));
        FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory + "\\Notepad.exe");


        // Print the file name and version number.
        Console.WriteLine("File: " + myFileVersionInfo.FileDescription + '\n' +
           "Version number: " + myFileVersionInfo.FileVersion);
    }

}
Visual C++
public:
   [PermissionSet(SecurityAction::Demand, Name="FullTrust")]
   void GetFileVersion()
   {
      // Get the file version for the notepad.
      FileVersionInfo^ myFileVersionInfo = FileVersionInfo::GetVersionInfo( "%systemroot%\\Notepad.exe" );

      // Print the file name and version number.
      textBox1->Text = String::Concat( "File: " + myFileVersionInfo->FileDescription + "\n" +
         "Version number: " + myFileVersionInfo->FileVersion );
   }
.NET Framework Security

Inheritance Hierarchy

System..::.Object
  System.Diagnostics..::.FileVersionInfo
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
See Also

Reference

Tags :


Community Content

Heath Stewart
Powershell
  

FUNCTION Get-FileVersion
{
# Get the file version for the notepad.
${MyfileVersionInfo} = [System.Diagnostics.FileVersionInfo]::GetVersionInfo( `
$( join-path ${env:systemroot} "notepad.exe" ) )



# Print the file name and version number.
Write-Host $("File: " + ${MyfileVersionInfo}.FileDescription + "`nVersion number: " + ${MyfileVersionInfo}.FileVersion)
}


Thomas Lee
Richer sample with PowerShell
<#
.SYNOPSIS
    This script gets and displays the file version information of a file
.DESCRIPTION
    This script calls System.Diagnostics.FileVersionInfo's 
    GetVersion info method on the file. By default, the file version
    displayed/returned is that of $systemroot%\notepad.exe. 
.NOTES
    File Name  : Get-FileVersionInfo.ps1
    Author     : Thomas Lee - tfl@psp.co.uk
    Requires   : PowerShell V2 CTP3
    Note       : The file named passed to GetVersionInfo needs to 
              be fully qualified, not just local name.
.LINK
    This script posted to:
      http://www.pshscripts.blogspot.com
    MSDN Sample posted at:
     http://msdn.microsoft.com/en-us/library/system.diagnostics.fileversioninfo.aspx
.EXAMPLE
    PSH [C:\foo]: .\Get-FileVersionInfo.ps1
    File Description : Notepad
    File Version     : 6.0.6000.16386 (vista_rtm.061101-2205)
.EXAMPLE
    PSH [C:\Foo]: .\Get-FileVersionInfo.ps1' c:\windows\fveupdate.exe
    File Description : BitLocker Drive Encryption Servicing Utility
    File Version     : 6.0.6000.16386 (vista_rtm.061101-2205)
.PARAMETER filename
    The name of the file for which file version information is displayed.
#>
param (
[string] $filename = $(join-path ${env:systemroot} "Notepad.Exe")
)

##
# start of script
##
$info= [System.Diagnostics.FileVersionInfo]::GetVersionInfo($filename)
"File Description : {0}" -f $info.filedescription
"File Version : {0}" -f $info.fileversion

Page view tracker