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.

Here is a screenshot of the issue. I have tested over 100 dll's and have noticed that sometimes it reports correctly, and sometimes it does not. Varies from dll to dll..

http://i46.tinypic.com/2vnkjgj.jpg

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.

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?

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

hmm it is cool

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.