惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - 找事的狐狸

“摸”电脑的时代(三):解析Surface内部结构 “摸”电脑的时代(二):多点触摸秀 写于Silverlight整装待发之际(八):也谈Silverlight人才招聘策略 WinHec扫盲贴 《WPF揭秘》勘误表 如何隐藏UpdatePanel 支付宝实名制实现思路 程序员的必备装备——为健康加油 [好书推荐] C#和.NET 2.0实战:平台、语言与框架 老调重弹——你存储的密码做Hash了吗? JavaScript的世界从来没有像现在这样精彩 CSS实现不同的打印和屏幕显示结果 [翻译] Vista中的音量II: Windows Vista音量种类 文件加密的简单实现(C语言) 闲话WPF近期发展 浅析Family Show 2.0的子窗体实现 WPF实现Tag Cloud 浅析Family Show 2.0的数据结构及基本算法 如何实现一个不规则形状的WPF窗口
如何检测是否安装了.NET 2.0和.NET 3.0
数字游民托尼 · 2007-10-07 · via 博客园 - 找事的狐狸

代码来自Paint.NET的PaintDotNet.SystemLayer.OS类

这段代码是通过检查注册表中的项来确定.NET 2.0/3.0是否安装的。由于Paint.NET是由微软员工参与开发的,可以认为这是比较准确的判断方法。大家借鉴一下检测方法就可以了,不用太在意实现,在C++中这种检测方法同样可以实现。

        private static bool IsDotNet2VersionInstalled(int major, int minor, int build)
        
{
            
const string regKeyNameFormat = "Software\\Microsoft\\NET Framework Setup\\NDP\\v{0}.{1}.{2}";
            
const string regValueName = "Install";

            
string regKeyName = string.Format(regKeyNameFormat, major.ToString(CultureInfo.InvariantCulture),
                minor.ToString(CultureInfo.InvariantCulture), build.ToString(CultureInfo.InvariantCulture));

            
return CheckForRegValueEquals1(regValueName, regKeyName);
        }


        
private static bool IsDotNet3VersionInstalled(int major, int minor, int build)
        
{
            
bool result = false;

            
const string regValueName = "InstallSuccess";

            
if (!result)
            
{
                
const string regKeyNameFormat = "Software\\Microsoft\\NET Framework Setup\\NDP\\v{0}.{1}\\Setup";
                
string regKeyName = string.Format(regKeyNameFormat, major, minor);

                result 
|= CheckForRegValueEquals1(regKeyName, regValueName);
            }


            
if (!result)
            
{
                
// There seems to be a bug in x64 .NET 3.0 where it only records its success in the 32-bit section of the registry.
                const string regKeyNameFormat2 = "Software\\Wow6432Node\\Microsoft\\NET Framework Setup\\NDP\\v{0}.{1}\\Setup";
                
string regKeyName2 = string.Format(regKeyNameFormat2, major, minor);

                result 
|= CheckForRegValueEquals1(regKeyName2, regValueName);
            }


            
return result;
        }


        
private static bool CheckForRegValueEquals1(string regKeyName, string regValueName)
        
{
            
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(regKeyName, false))
            
{
                
object value = null;

                
if (key != null)
                
{
                    value 
= key.GetValue(regValueName);
                }


                
return (value != null && value is int && (int)value == 1);
            }

        }