如何使用VC++写一个小程序来检测.NetFrameWork版本

 我来答
受司大人
推荐于2016-11-26 · 知道合伙人影视综艺行家
受司大人
知道合伙人影视综艺行家
采纳数:20262 获赞数:171843
毕业于浙江广厦,有一定的电脑专业基础和两年工作经验,读过相关书籍多本

向TA提问 私信TA
展开全部
如何使用VC来检测系统上的.NetFrameWork版本呢,原理见我前面刚刚写过,不懂的可以去看一下,下面直接贴代码了,百度呀,为什么没有贴代码的功能呢,哎直接贴真恶心呀,那就恶心一下吧。
#include “stdio.h”
#include “windows.h”
#include “tchar.h”
#include “strsafe.h”
#include “stdafx.h”

// 为避免机器编译时候出现:SDK中某些值没有被定义的情况,先定义他们。
#ifndef SM_TABLETPC
#define SM_TABLETPC 86
#endif
#ifndef SM_MEDIACENTER
#define SM_MEDIACENTER 87
#endif
// 用于检测注册表项的名称和值名称的常量
const TCHAR *g_szNetfx10RegKeyName = _T(“Software\\Microsoft\\.NETFramework\\Policy\\v1.0″);
const TCHAR *g_szNetfx10RegKeyValue = _T(“3705″);
const TCHAR *g_szNetfx10SPxMSIRegKeyName = _T(“Software\\Microsoft\\Active Setup\\Installed Components\\{78705f0d-e8db-4b2d-8193-982bdda15ecd}”);
const TCHAR *g_szNetfx10SPxOCMRegKeyName = _T(“Software\\Microsoft\\Active Setup\\Installed Components\\{FDC11A6F-17D1-48f9-9EA3-9051954BAA24}”);
const TCHAR *g_szNetfx11RegKeyName = _T(“Software\\Microsoft\\NET Framework Setup\\NDP\\v1.1.4322″);
const TCHAR *g_szNetfx20RegKeyName = _T(“Software\\Microsoft\\NET Framework Setup\\NDP\\v2.0.50727″);
const TCHAR *g_szNetfx30RegKeyName = _T(“Software\\Microsoft\\NET Framework Setup\\NDP\\v3.0\\Setup”);
const TCHAR *g_szNetfx30SpRegKeyName = _T(“Software\\Microsoft\\NET Framework Setup\\NDP\\v3.0″);
const TCHAR *g_szNetfx30RegValueName = _T(“InstallSuccess”);
const TCHAR *g_szNetfx35RegKeyName = _T(“Software\\Microsoft\\NET Framework Setup\\NDP\\v3.5″);
const TCHAR *g_szNetfxStandardRegValueName = _T(“Install”);
const TCHAR *g_szNetfxStandardSPxRegValueName = _T(“SP”);
const TCHAR *g_szNetfxStandardVersionRegValueName = _T(“Version”);
// .NET Framework 3.0最终版本的版本信息
const int g_iNetfx30VersionMajor = 3;
const int g_iNetfx30VersionMinor = 0;
const int g_iNetfx30VersionBuild = 4506;
const int g_iNetfx30VersionRevision = 26;
// .NET Framework 3.5最终版本的版本信息
const int g_iNetfx35VersionMajor = 3;
const int g_iNetfx35VersionMinor = 5;
const int g_iNetfx35VersionBuild = 21022;
const int g_iNetfx35VersionRevision = 8;
// 函数原型声明
bool CheckNetfxBuildNumber(const TCHAR*, const TCHAR*, const int, const int, const int, const int);
int GetNetfx10SPLevel();
int GetNetfxSPLevel(const TCHAR*, const TCHAR*);
bool IsCurrentOSTabletMedCenter();
bool IsNetfx10Installed();
bool IsNetfx11Installed();
bool IsNetfx20Installed();
bool IsNetfx30Installed();
bool IsNetfx35Installed();
bool RegistryGetValue(HKEY, const TCHAR*, const TCHAR*, DWORD, LPBYTE, DWORD);
/******************************************************************
Function Name: 判断.NET Framework 1.0是否安装
Description: Uses the detection method recommended at
[url]http://msdn.microsoft.com/library/ms994349.aspx[/url]
to determine whether the .NET Framework 1.0 is
installed on the machine
Inputs: NONE
Results: .NET Framework 1.0已安装返回TRUE否则返回FALSE
******************************************************************/
bool IsNetfx10Installed()
{
TCHAR szRegValue[MAX_PATH];
return (RegistryGetValue(HKEY_LOCAL_MACHINE, g_szNetfx10RegKeyName, g_szNetfx10RegKeyValue, NULL, (LPBYTE)szRegValue, MAX_PATH));
}
/******************************************************************
Function Name: 判断.NET Framework 1.1是否安装
Description: Uses the detection method recommended at
[url]http://msdn.microsoft.com/library/ms994339.aspx[/url]
to determine whether the .NET Framework 1.1 is
installed on the machine
Inputs: NONE
Results: .NET Framework 1.1已安装返回TRUE否则返回FALSE
******************************************************************/
bool IsNetfx11Installed()
{
bool bRetValue = false;
DWORD dwRegValue=0;
if (RegistryGetValue(HKEY_LOCAL_MACHINE, g_szNetfx11RegKeyName, g_szNetfxStandardRegValueName, NULL, (LPBYTE)&dwRegValue, sizeof(DWORD)))
{
if (1 == dwRegValue)
bRetValue = true;
}
return bRetValue;
}
/******************************************************************
Function Name: 判断.NET Framework 2.0是否安装
Description: Uses the detection method recommended at
[url]http://msdn.microsoft.com/library/aa480243.aspx[/url]
to determine whether the .NET Framework 2.0 is
installed on the machine
Inputs: NONE
Results: .NET Framework 2.0已安装返回TRUE否则返回FALSE
******************************************************************/
bool IsNetfx20Installed()
{
bool bRetValue = false;
DWORD dwRegValue=0;
if (RegistryGetValue(HKEY_LOCAL_MACHINE, g_szNetfx20RegKeyName, g_szNetfxStandardRegValueName, NULL, (LPBYTE)&dwRegValue, sizeof(DWORD)))
{
if (1 == dwRegValue)
bRetValue = true;
}
return bRetValue;
}
/******************************************************************
Function Name: 判断.NET Framework 3.0是否安装
Description: Uses the detection method recommended at
[url]http://msdn.microsoft.com/library/aa964979.aspx[/url]
to determine whether the .NET Framework 3.0 is
installed on the machine
Inputs: NONE
Results: .NET Framework 3.0已安装返回TRUE否则返回FALSE
******************************************************************/
bool IsNetfx30Installed()
{
bool bRetValue = false;
DWORD dwRegValue=0;
// 检查InstallSuccess注册表值存在,等于1
if (RegistryGetValue(HKEY_LOCAL_MACHINE, g_szNetfx30RegKeyName, g_szNetfx30RegValueName, NULL, (LPBYTE)&dwRegValue, sizeof(DWORD)))
{
if (1 == dwRegValue)
bRetValue = true;
}
//补充核查,检查版本列出的版本号在注册表中,是否已有预发布版的 .NET Framework 3.0 InstallSuccess值。
return (bRetValue && CheckNetfxBuildNumber(g_szNetfx30RegKeyName, g_szNetfxStandardVersionRegValueName, g_iNetfx30VersionMajor, g_iNetfx30VersionMinor, g_iNetfx30VersionBuild, g_iNetfx30VersionRevision));
}
/******************************************************************
Function Name: 判断.NET Framework 3.5是否安装
Description: Uses the detection method recommended at
[url]http://msdn.microsoft.com/library/cc160716.aspx[/url]
to determine whether the .NET Framework 3.5 is
installed on the machine
Inputs: NONE
Results: .NET Framework 3.5已安装返回TRUE否则返回FALSE
******************************************************************/
bool IsNetfx35Installed()
{
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式