0

Using: Visual Basic .NET 2012

Problem: I am using the code below to get the version information from a system dll. It returns a version number and I check the file manually by going to C:\windows\system32, right clicking, going to properties, clicking on Details and the version number that VB.NET returned to me is not the one shown here. What is up?

    Dim dnsFile = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\dnsapi.dll"
    Dim myFileVersionInfo As FileVersionInfo
    If File.Exists(dnsFile) Then
        myFileVersionInfo = FileVersionInfo.GetVersionInfo(dnsFile)
        FileVersion = (myFileVersionInfo.FileVersion.Split(" ")(0)).ToString
    End If

    MsgBox(FileVersion)

Does anyone know why this is going on? I need to retrieve the version number shown to me in the Properties menu.

1
Contributor
4
Replies
17
Views
4 Years
Discussion Span
Last Post by LucianAdamson
0

I still have no idea why this code (and the code given by Microsoft MSDN, which is similiar) is giving off wrong FileVersion and ProductVersion numbers.

0

Ok, found out how to get the proper file version through experimentation, but I don't understand why this works and the other method doesn't. Here is the new code to get the version number.

FileVersion = myFileVersionInfo.FileMajorPart.ToString & "." & myFileVersionInfo.FileMinorPart.ToString & "." & myFileVersionInfo.FileBuildPart.ToString & "." & myFileVersionInfo.FilePrivatePart.ToString

Versus the old one above (shown below too) that gives a different version number.

FileVersion = (myFileVersionInfo.FileVersion.Split(" ")(0)).ToString

Can anyone explain this?

0

I found that using version numbers for this particular project was a bad idea.. switched to MD5 hashes.. marking as solved now

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.