/// <summary>
/// 检测是否安裝4.7.2以上版本
/// </summary>
/// <returns></returns>
bool CheckNet472()
{
//C:\Windows\Microsoft.NET\Framework
string net = "Microsoft.NET";
string mscorlibFile = "mscorlib.dll";
string RuntimeDirectory = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
int index = RuntimeDirectory.IndexOf(net);
if (index == -1)
{
MessageBox.Show(RuntimeDirectory, "錯誤,找不到系统路径");
return false;
}
string NetDirectory = RuntimeDirectory.Substring(0, index + net.Length);
string Framework = Path.Combine(Path.Combine(NetDirectory, Path.Combine("Framework", "v4.0.30319")), mscorlibFile);
string Framework64 = Path.Combine(Path.Combine(NetDirectory, Path.Combine("Framework64", "v4.0.30319")), mscorlibFile);
int Nub = 0;
if (File.Exists(Framework))
{
Nub = GetFileVersion(Framework);
}
else if (File.Exists(Framework64))
{
Nub = GetFileVersion(Framework64);
}
if (Nub > 471)
{
return true;
}
else
{
return false;
}
}
int GetFileVersion(string FilePath)
{
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(FilePath);
string Version = fileVersionInfo.ProductVersion;
string res = new string(Version.Where(char.IsDigit).ToArray());
if (res.Length > 1)
{
int NubCode = Convert.ToInt32(res.Substring(0, 3));
return NubCode;
}
return 0;
}