最近有个需求,需要验证客户端是否安装了DotNet 3.5。一开始本来打算用DotNetmscoree.dll里的GetCORVersion判断,不过实际测试了一下,发现GetCORVersion返回的是的当前系统CLR的版本号,由于DotNet 3.5本质上还是CLR 2.0,所以返回的结果是2.0。
爬网半天,发现还是用注册表的方式最稳定。主要思路是:DotNet 3.5安装完毕后,会在注册表中创建HKLMSOFTWAREMicrosoftNET Framework SetupNDPv3.5,如果这个目录下有个Install的key等于1,那说明3.5已经安装。
Code Snippet
- public static bool IsDotNet35Installed()
- {
- bool dotNet35Installed = false;
- string dotnet35KeyName = @”SoftwareMicrosoftNET Framework SetupNDPv3.5″;
- string dotnet35ValueName = “Install”;
- string dotnet35Value = GetRegValue(dotnet35KeyName, dotnet35ValueName);
- if (dotnet35Value == “1”)
- {
- dotNet35Installed = true;
- }
- return dotNet35Installed;
- }
同理,如果要检查DotNet 4.0是否安装,只需要把对应的key修改成HKLMSOFTWAREMicrosoftNET Framework SetupNDPv4Full。
Leave a Reply
You must be logged in to post a comment.