日期:2014-05-19  浏览次数:20757 次

获取exe文件的版本号问题
string   path   =   @ "D:\Test\folder2\IPMSG.exe ";  

try
                {        
                        System.Diagnostics.FileVersionInfo   file1   =   System.Diagnostics.FileVersionInfo.GetVersionInfo(path);
                        FileVersions   =   file1.FileVersion;
                }
catch(Exception   e1)
                {
                        FileVersions   =   " ";
                }

                MessageBox.Show(FileVersions);

IPMSG.exe在属性里查看的版本号为2.0.6.0,
运行程序得到的是2.06
另外有的exe文件版本号就给完整的,有的就给不完整的,还有的把 ". "替换成了 ", "
怎么回事?

------解决方案--------------------
http://www.cnblogs.com/zbqy/archive/2007/02/03/638835.aspx
看一下这个
------解决方案--------------------
string FileVersions = " ";
string path = @ "E:\GoDVB\Latest\Multicast发送端.exe ";

try
{
System.Diagnostics.FileVersionInfo file1 = System.Diagnostics.FileVersionInfo.GetVersionInfo(path);
FileVersions = file1.FileVersion;
}
catch (Exception)
{
FileVersions = " ";
}

MessageBox.Show(FileVersions);

// 结果是1.0.6.0,而不是1.06呀? 刚刚试过了。
------解决方案--------------------
楼主,你的程序没有问题.
之所以出现不一致的情况
是因为你没仔细看清IPMSG.exe的版本号
在其他版本信息框中版本信息才是真正的版本号,也是程序所能获得版本号.因此是2.06


你问为什么会出现2.0.6.0这样的版本.这是为了遵循微软的版本标准,即
版本号显示为“主版本号.次版本号.内部版本号.专用部件号”。


接分
------解决方案--------------------
string FileVersions = " ";
string path = @ "E:\GoDVB\Latest\Multicast发送端.exe ";

try
{
System.Diagnostics.FileVersionInfo file1 = System.Diagnostics.FileVersionInfo.GetVersionInfo(path);
FileVersions = String.Format( "{0}.{1}.{2}.{3} ", file1.FileMajorPart, file1.FileMinorPart, file1.FileBuildPart, file1.FilePrivatePart);
}
catch (Exception)
{
FileVersions = " ";
}

MessageBox.Show(FileVersions);