diff --git a/SysInfoDetector.sln b/SysInfoDetector.sln new file mode 100644 index 0000000..84fcb5b --- /dev/null +++ b/SysInfoDetector.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SysInfoDetector", "SysInfoDetector\SysInfoDetector.vcproj", "{75958EB9-73F2-437B-B7E0-D57E2B2C4CF8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {75958EB9-73F2-437B-B7E0-D57E2B2C4CF8}.Debug|Win32.ActiveCfg = Debug|Win32 + {75958EB9-73F2-437B-B7E0-D57E2B2C4CF8}.Debug|Win32.Build.0 = Debug|Win32 + {75958EB9-73F2-437B-B7E0-D57E2B2C4CF8}.Release|Win32.ActiveCfg = Release|Win32 + {75958EB9-73F2-437B-B7E0-D57E2B2C4CF8}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/SysInfoDetector/SysInfo.cpp b/SysInfoDetector/SysInfo.cpp new file mode 100644 index 0000000..faafcb9 --- /dev/null +++ b/SysInfoDetector/SysInfo.cpp @@ -0,0 +1,222 @@ +#include "StdAfx.h" +#include "SysInfo.h" +#include +#include + +typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); +typedef BOOL(WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD); + +CSysInfo::CSysInfo() +{ +} + +CSysInfo::~CSysInfo() +{ +} + +SystemInfoDef* CSysInfo::GetAll() +{ + GetDotNetFramework(); + return &m_info; +} + +WCHAR* CSysInfo::GetFxVersionGreaterThen4dot5(DWORD release) const { + switch (release) { + case 378389: //4.5 + return L".NET Framework 4.5"; + case 378675: //4.5.1 installed with Windows 8.1 or Windows Server 2012 R2 + case 378758: //4.5.1 installed on Windows 8, Windows 7 SP1, or Windows Vista SP2 + return L".NET Framework 4.5.1"; + case 379893: //4.5.2 + return L".NET Framework 4.5.2"; + case 393295: //4.6 on Windows 10 + case 393297: //4.6 on all other OS + return L".NET Framework 4.6"; + case 394254: //4.6.1 on Windows 10 November Update systems + case 394271: //4.6.1 on all other OS versions + return L".NET Framework 4.6.1"; + case 394802: //4.6.2 on Windows 10 Anniversary Update + case 394806: //4.6.2 on on all other OS versions + return L".NET Framework 4.6.2"; + default: //Unknown + return L".NET Framework > 4.6.2?"; + } +} + +WCHAR* GetDotNetFramework() +{ + WCHAR szDotNetFramework[DOTNET_INFO_LENGTH]; + + DWORD dwInstall; + DWORD dwRelease; + DWORD dwSP; + DWORD dwSize; + HKEY hkResult; + + //¼ì²â HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322\Install - 1 + // else if(HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322\SP - 1) + // => .NET Framework 1.1 Service Pack 1 + // else + // => .NET Framework 1.1 + if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v1.1.4322", 0, KEY_READ, &hkResult)) + { + dwSize = sizeof(dwInstall); + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Install", 0, 0, (LPBYTE)&dwInstall, &dwSize) && 1 == dwInstall) + { + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"SP", 0, 0, (LPBYTE)&dwSP, &dwSize) && 1 == dwSP) + { + StringCchCatW(m_info.szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 1.1 Service Pack 1\r\n"); + } + else + { + StringCchCatW(m_info.szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 1.1\r\n"); + } + } + RegCloseKey(hkResult); + } + + //¼ì²â HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727\Install - 1 + // if(HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727\SP - 2) + // => .NET Framework 2.0 Service Pack 2 + // else if(HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727\SP - 1) + // => .NET Framework 2.0 Service Pack 1 + // else + // => .NET Framework 2.0 + if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v2.0.50727", 0, KEY_READ, &hkResult)) + { + dwSize = sizeof(dwInstall); + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Install", 0, 0, (LPBYTE)&dwInstall, &dwSize) && 1 == dwInstall) + { + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"SP", 0, 0, (LPBYTE)&dwSP, &dwSize) && (2 == dwSP || 1 == dwSP)) + { + if (2 == dwSP) + { + StringCchCatW(m_info.szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 2.0 Service Pack 2\r\n"); + } + else + { + StringCchCatW(m_info.szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 2.0 Service Pack 1\r\n"); + } + } + else + { + StringCchCatW(m_info.szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 2.0\r\n"); + } + } + RegCloseKey(hkResult); + } + + //¼ì²â HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Install - 1 + // if(HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\SP - 2) + // => .NET Framework 3.0 Service Pack 2 + // else if(HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\SP - 1) + // => .NET Framework 3.0 Service Pack 1 + // else + // => .NET Framework 3.0 + if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3.0", 0, KEY_READ, &hkResult)) + { + dwSize = sizeof(dwInstall); + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Install", 0, 0, (LPBYTE)&dwInstall, &dwSize) && 1 == dwInstall) + { + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"SP", 0, 0, (LPBYTE)&dwSP, &dwSize) && (2 == dwSP || 1 == dwSP)) + { + if (2 == dwSP) + { + StringCchCatW(m_info.szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 3.0 Service Pack 2\r\n"); + } + else + { + StringCchCatW(m_info.szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 3.0 Service Pack 1\r\n"); + } + } + else + { + StringCchCatW(m_info.szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 3.0\r\n"); + } + } + RegCloseKey(hkResult); + } + + //¼ì²â HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5\Install - 1 + // if(HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5\SP - 1) + // => .NET Framework 3.5 Service Pack 1 + // else + // => .NET Framework 3.5 + if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3.5", 0, KEY_READ, &hkResult)) + { + dwSize = sizeof(dwInstall); + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Install", 0, 0, (LPBYTE)&dwInstall, &dwSize) && 1 == dwInstall) + { + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"SP", 0, 0, (LPBYTE)&dwSP, &dwSize) && 1 == dwSP) + { + StringCchCatW(m_info.szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 3.5 Service Pack 1\r\n"); + } + else + { + StringCchCatW(m_info.szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 3.5\r\n"); + } + } + RegCloseKey(hkResult); + } + + //¼ì²â HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4.0\Client\Install - 1 + // => .NET Framework 4.0 Client Profile + if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4.0\\Client", 0, KEY_READ, &hkResult)) + { + dwSize = sizeof(dwInstall); + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Install", 0, 0, (LPBYTE)&dwInstall, &dwSize) && 1 == dwInstall) + { + StringCchCatW(m_info.szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 4.0 Client Profile\r\n"); + } + RegCloseKey(hkResult); + } + + //¼ì²â HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4.0\Full\Install - 1 + // => .NET Framework 4.0 Full + if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4.0\\Full", 0, KEY_READ, &hkResult)) + { + dwSize = sizeof(dwInstall); + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Install", 0, 0, (LPBYTE)&dwInstall, &dwSize) && 1 == dwInstall) + { + StringCchCatW(m_info.szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 4.0 Full\r\n"); + } + RegCloseKey(hkResult); + } + + //¼ì²â HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client\Install - 1 + // switch(HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client\Release) + // => .NET Framework 4.5/4.5.1/4.5.2/4.6/4.6.1 Client Profile + if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Client", 0, KEY_READ, &hkResult)) + { + dwSize = sizeof(dwInstall); + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Install", 0, 0, (LPBYTE)&dwInstall, &dwSize) && 1 == dwInstall) + { + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Release", 0, 0, (LPBYTE)&dwRelease, &dwSize)) + { + StringCchCatW(m_info.szDotNetFramework, DOTNET_INFO_LENGTH, GetFxVersionGreaterThen4dot5(dwRelease)); + StringCchCatW(m_info.szDotNetFramework, DOTNET_INFO_LENGTH, L" Client Profile\r\n"); + } + } + RegCloseKey(hkResult); + } + + //¼ì²â HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\Install - 1 + // switch(HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\Release) + // => .NET Framework 4.5/4.5.1/4.5.2/4.6/4.6.1 Full + if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full", 0, KEY_READ, &hkResult)) + { + dwSize = sizeof(dwInstall); + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Install", 0, 0, (LPBYTE)&dwInstall, &dwSize) && 1 == dwInstall) + { + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Release", 0, 0, (LPBYTE)&dwRelease, &dwSize)) + { + StringCchCatW(m_info.szDotNetFramework, DOTNET_INFO_LENGTH, GetFxVersionGreaterThen4dot5(dwRelease)); + StringCchCatW(m_info.szDotNetFramework, DOTNET_INFO_LENGTH, L" Full\r\n"); + } + } + RegCloseKey(hkResult); + } + + return szDotNetFramework; +} + diff --git a/SysInfoDetector/SysInfo.h b/SysInfoDetector/SysInfo.h new file mode 100644 index 0000000..968d11b --- /dev/null +++ b/SysInfoDetector/SysInfo.h @@ -0,0 +1,158 @@ +#pragma once + +#pragma once + +#define WINDOWS_INFO_LENGTH 128 +#define DOTNET_INFO_LENGTH 1024 + +//Copied from Windows 10 SDK's winnt.h + +#define PRODUCT_UNDEFINED 0x00000000 + +#define PRODUCT_ULTIMATE 0x00000001 +#define PRODUCT_HOME_BASIC 0x00000002 +#define PRODUCT_HOME_PREMIUM 0x00000003 +#define PRODUCT_ENTERPRISE 0x00000004 +#define PRODUCT_HOME_BASIC_N 0x00000005 +#define PRODUCT_BUSINESS 0x00000006 +#define PRODUCT_STANDARD_SERVER 0x00000007 +#define PRODUCT_DATACENTER_SERVER 0x00000008 +#define PRODUCT_SMALLBUSINESS_SERVER 0x00000009 +#define PRODUCT_ENTERPRISE_SERVER 0x0000000A +#define PRODUCT_STARTER 0x0000000B +#define PRODUCT_DATACENTER_SERVER_CORE 0x0000000C +#define PRODUCT_STANDARD_SERVER_CORE 0x0000000D +#define PRODUCT_ENTERPRISE_SERVER_CORE 0x0000000E +#define PRODUCT_ENTERPRISE_SERVER_IA64 0x0000000F +#define PRODUCT_BUSINESS_N 0x00000010 +#define PRODUCT_WEB_SERVER 0x00000011 +#define PRODUCT_CLUSTER_SERVER 0x00000012 +#define PRODUCT_HOME_SERVER 0x00000013 +#define PRODUCT_STORAGE_EXPRESS_SERVER 0x00000014 +#define PRODUCT_STORAGE_STANDARD_SERVER 0x00000015 +#define PRODUCT_STORAGE_WORKGROUP_SERVER 0x00000016 +#define PRODUCT_STORAGE_ENTERPRISE_SERVER 0x00000017 +#define PRODUCT_SERVER_FOR_SMALLBUSINESS 0x00000018 +#define PRODUCT_SMALLBUSINESS_SERVER_PREMIUM 0x00000019 +#define PRODUCT_HOME_PREMIUM_N 0x0000001A +#define PRODUCT_ENTERPRISE_N 0x0000001B +#define PRODUCT_ULTIMATE_N 0x0000001C +#define PRODUCT_WEB_SERVER_CORE 0x0000001D +#define PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT 0x0000001E +#define PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY 0x0000001F +#define PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING 0x00000020 +#define PRODUCT_SERVER_FOUNDATION 0x00000021 +#define PRODUCT_HOME_PREMIUM_SERVER 0x00000022 +#define PRODUCT_SERVER_FOR_SMALLBUSINESS_V 0x00000023 +#define PRODUCT_STANDARD_SERVER_V 0x00000024 +#define PRODUCT_DATACENTER_SERVER_V 0x00000025 +#define PRODUCT_ENTERPRISE_SERVER_V 0x00000026 +#define PRODUCT_DATACENTER_SERVER_CORE_V 0x00000027 +#define PRODUCT_STANDARD_SERVER_CORE_V 0x00000028 +#define PRODUCT_ENTERPRISE_SERVER_CORE_V 0x00000029 +#define PRODUCT_HYPERV 0x0000002A +#define PRODUCT_STORAGE_EXPRESS_SERVER_CORE 0x0000002B +#define PRODUCT_STORAGE_STANDARD_SERVER_CORE 0x0000002C +#define PRODUCT_STORAGE_WORKGROUP_SERVER_CORE 0x0000002D +#define PRODUCT_STORAGE_ENTERPRISE_SERVER_CORE 0x0000002E +#define PRODUCT_STARTER_N 0x0000002F +#define PRODUCT_PROFESSIONAL 0x00000030 +#define PRODUCT_PROFESSIONAL_N 0x00000031 +#define PRODUCT_SB_SOLUTION_SERVER 0x00000032 +#define PRODUCT_SERVER_FOR_SB_SOLUTIONS 0x00000033 +#define PRODUCT_STANDARD_SERVER_SOLUTIONS 0x00000034 +#define PRODUCT_STANDARD_SERVER_SOLUTIONS_CORE 0x00000035 +#define PRODUCT_SB_SOLUTION_SERVER_EM 0x00000036 +#define PRODUCT_SERVER_FOR_SB_SOLUTIONS_EM 0x00000037 +#define PRODUCT_SOLUTION_EMBEDDEDSERVER 0x00000038 +#define PRODUCT_SOLUTION_EMBEDDEDSERVER_CORE 0x00000039 +#define PRODUCT_PROFESSIONAL_EMBEDDED 0x0000003A +#define PRODUCT_ESSENTIALBUSINESS_SERVER_MGMT 0x0000003B +#define PRODUCT_ESSENTIALBUSINESS_SERVER_ADDL 0x0000003C +#define PRODUCT_ESSENTIALBUSINESS_SERVER_MGMTSVC 0x0000003D +#define PRODUCT_ESSENTIALBUSINESS_SERVER_ADDLSVC 0x0000003E +#define PRODUCT_SMALLBUSINESS_SERVER_PREMIUM_CORE 0x0000003F +#define PRODUCT_CLUSTER_SERVER_V 0x00000040 +#define PRODUCT_EMBEDDED 0x00000041 +#define PRODUCT_STARTER_E 0x00000042 +#define PRODUCT_HOME_BASIC_E 0x00000043 +#define PRODUCT_HOME_PREMIUM_E 0x00000044 +#define PRODUCT_PROFESSIONAL_E 0x00000045 +#define PRODUCT_ENTERPRISE_E 0x00000046 +#define PRODUCT_ULTIMATE_E 0x00000047 +#define PRODUCT_ENTERPRISE_EVALUATION 0x00000048 +#define PRODUCT_MULTIPOINT_STANDARD_SERVER 0x0000004C +#define PRODUCT_MULTIPOINT_PREMIUM_SERVER 0x0000004D +#define PRODUCT_STANDARD_EVALUATION_SERVER 0x0000004F +#define PRODUCT_DATACENTER_EVALUATION_SERVER 0x00000050 +#define PRODUCT_ENTERPRISE_N_EVALUATION 0x00000054 +#define PRODUCT_EMBEDDED_AUTOMOTIVE 0x00000055 +#define PRODUCT_EMBEDDED_INDUSTRY_A 0x00000056 +#define PRODUCT_THINPC 0x00000057 +#define PRODUCT_EMBEDDED_A 0x00000058 +#define PRODUCT_EMBEDDED_INDUSTRY 0x00000059 +#define PRODUCT_EMBEDDED_E 0x0000005A +#define PRODUCT_EMBEDDED_INDUSTRY_E 0x0000005B +#define PRODUCT_EMBEDDED_INDUSTRY_A_E 0x0000005C +#define PRODUCT_STORAGE_WORKGROUP_EVALUATION_SERVER 0x0000005F +#define PRODUCT_STORAGE_STANDARD_EVALUATION_SERVER 0x00000060 +#define PRODUCT_CORE_ARM 0x00000061 +#define PRODUCT_CORE_N 0x00000062 +#define PRODUCT_CORE_COUNTRYSPECIFIC 0x00000063 +#define PRODUCT_CORE_SINGLELANGUAGE 0x00000064 +#define PRODUCT_CORE 0x00000065 +#define PRODUCT_PROFESSIONAL_WMC 0x00000067 +#define PRODUCT_MOBILE_CORE 0x00000068 +#define PRODUCT_EMBEDDED_INDUSTRY_EVAL 0x00000069 +#define PRODUCT_EMBEDDED_INDUSTRY_E_EVAL 0x0000006A +#define PRODUCT_EMBEDDED_EVAL 0x0000006B +#define PRODUCT_EMBEDDED_E_EVAL 0x0000006C +#define PRODUCT_NANO_SERVER 0x0000006D +#define PRODUCT_CLOUD_STORAGE_SERVER 0x0000006E +#define PRODUCT_CORE_CONNECTED 0x0000006F +#define PRODUCT_PROFESSIONAL_STUDENT 0x00000070 +#define PRODUCT_CORE_CONNECTED_N 0x00000071 +#define PRODUCT_PROFESSIONAL_STUDENT_N 0x00000072 +#define PRODUCT_CORE_CONNECTED_SINGLELANGUAGE 0x00000073 +#define PRODUCT_CORE_CONNECTED_COUNTRYSPECIFIC 0x00000074 +#define PRODUCT_CONNECTED_CAR 0x00000075 +#define PRODUCT_INDUSTRY_HANDHELD 0x00000076 +#define PRODUCT_PPI_PRO 0x00000077 +#define PRODUCT_ARM64_SERVER 0x00000078 +#define PRODUCT_EDUCATION 0x00000079 +#define PRODUCT_EDUCATION_N 0x0000007A +#define PRODUCT_IOTUAP 0x0000007B +#define PRODUCT_CLOUD_HOST_INFRASTRUCTURE_SERVER 0x0000007C +#define PRODUCT_ENTERPRISE_S 0x0000007D +#define PRODUCT_ENTERPRISE_S_N 0x0000007E +#define PRODUCT_PROFESSIONAL_S 0x0000007F +#define PRODUCT_PROFESSIONAL_S_N 0x00000080 +#define PRODUCT_ENTERPRISE_S_EVALUATION 0x00000081 +#define PRODUCT_ENTERPRISE_S_N_EVALUATION 0x00000082 +#define PRODUCT_HOLOGRAPHIC 0x00000087 + +#define PRODUCT_UNLICENSED 0xABCDABCD + +//Windows 10 SDKµÄwinnt.h¾ÓÈ»»¹È±ÕâÁ½¸ö(?) +#define PRODUCT_IOTUAPCOMMERCIAL 0x00000083 +#define PRODUCT_MOBILE_ENTERPRISE 0x00000085 + +struct SystemInfoDef +{ + WCHAR szDotNetFramework[DOTNET_INFO_LENGTH]; +}; + +class CSysInfo +{ +public: + CSysInfo(); + ~CSysInfo(); + + SystemInfoDef* GetAll(); + +private: + WCHAR* CSysInfo::GetFxVersionGreaterThen4dot5(DWORD release) const; + void GetDotNetFramework(); + + SystemInfoDef m_info; +}; diff --git a/SysInfoDetector/SysInfoDetector.cpp b/SysInfoDetector/SysInfoDetector.cpp new file mode 100644 index 0000000..075617d --- /dev/null +++ b/SysInfoDetector/SysInfoDetector.cpp @@ -0,0 +1,232 @@ +#include "stdafx.h" +#include +#include + +#define DOTNET_INFO_LENGTH 1024 + +WCHAR szDotNetFramework[DOTNET_INFO_LENGTH]; + +WCHAR* GetFxVersionGreaterThen4dot5(DWORD release) +{ + switch (release) { + case 378389: //4.5 + return L".NET Framework 4.5"; + case 378675: //4.5.1 installed with Windows 8.1 or Windows Server 2012 R2 + case 378758: //4.5.1 installed on Windows 8, Windows 7 SP1, or Windows Vista SP2 + return L".NET Framework 4.5.1"; + case 379893: //4.5.2 + return L".NET Framework 4.5.2"; + case 393295: //4.6 on Windows 10 + case 393297: //4.6 on all other OS + return L".NET Framework 4.6"; + case 394254: //4.6.1 on Windows 10 November Update systems + case 394271: //4.6.1 on all other OS versions + return L".NET Framework 4.6.1"; + case 394802: //4.6.2 on Windows 10 Anniversary Update + case 394806: //4.6.2 on all other OS versions + return L".NET Framework 4.6.2"; + case 460798: //4.7 on Windows 10 Creators Update + case 460805: //4.7 on all other OS versions. + return L".NET Framework 4.7"; + case 461308: //4.7.1 on Windows 10 Fall Creators Update + case 461310: //4.7.1 on all other OS versions. + return L".NET Framework 4.7.1"; + case 461808: //4.7.2 on Windows 10 April 2018 Update + case 461814: //4.7.2 on all other OS versions. + return L".NET Framework 4.7.2"; + default: //Unknown + return L".NET Framework > 4.7.2"; + } +} + +WCHAR* GetDotNetFramework() +{ + DWORD dwInstall; + DWORD dwRelease; + DWORD dwSP; + DWORD dwSize; + HKEY hkResult; + + //¼ì²â HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322\Install - 1 + // else if(HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322\SP - 1) + // => .NET Framework 1.1 Service Pack 1 + // else + // => .NET Framework 1.1 + if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v1.1.4322", 0, KEY_READ, &hkResult)) + { + dwSize = sizeof(dwInstall); + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Install", 0, 0, (LPBYTE)&dwInstall, &dwSize) && 1 == dwInstall) + { + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"SP", 0, 0, (LPBYTE)&dwSP, &dwSize) && 1 == dwSP) + { + StringCchCatW(szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 1.1 Service Pack 1\r\n"); + } + else + { + StringCchCatW(szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 1.1\r\n"); + } + } + RegCloseKey(hkResult); + } + + //¼ì²â HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727\Install - 1 + // if(HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727\SP - 2) + // => .NET Framework 2.0 Service Pack 2 + // else if(HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727\SP - 1) + // => .NET Framework 2.0 Service Pack 1 + // else + // => .NET Framework 2.0 + if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v2.0.50727", 0, KEY_READ, &hkResult)) + { + dwSize = sizeof(dwInstall); + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Install", 0, 0, (LPBYTE)&dwInstall, &dwSize) && 1 == dwInstall) + { + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"SP", 0, 0, (LPBYTE)&dwSP, &dwSize) && (2 == dwSP || 1 == dwSP)) + { + if (2 == dwSP) + { + StringCchCatW(szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 2.0 Service Pack 2\r\n"); + } + else + { + StringCchCatW(szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 2.0 Service Pack 1\r\n"); + } + } + else + { + StringCchCatW(szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 2.0\r\n"); + } + } + RegCloseKey(hkResult); + } + + //¼ì²â HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Install - 1 + // if(HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\SP - 2) + // => .NET Framework 3.0 Service Pack 2 + // else if(HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\SP - 1) + // => .NET Framework 3.0 Service Pack 1 + // else + // => .NET Framework 3.0 + if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3.0", 0, KEY_READ, &hkResult)) + { + dwSize = sizeof(dwInstall); + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Install", 0, 0, (LPBYTE)&dwInstall, &dwSize) && 1 == dwInstall) + { + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"SP", 0, 0, (LPBYTE)&dwSP, &dwSize) && (2 == dwSP || 1 == dwSP)) + { + if (2 == dwSP) + { + StringCchCatW(szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 3.0 Service Pack 2\r\n"); + } + else + { + StringCchCatW(szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 3.0 Service Pack 1\r\n"); + } + } + else + { + StringCchCatW(szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 3.0\r\n"); + } + } + RegCloseKey(hkResult); + } + + //¼ì²â HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5\Install - 1 + // if(HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5\SP - 1) + // => .NET Framework 3.5 Service Pack 1 + // else + // => .NET Framework 3.5 + if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v3.5", 0, KEY_READ, &hkResult)) + { + dwSize = sizeof(dwInstall); + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Install", 0, 0, (LPBYTE)&dwInstall, &dwSize) && 1 == dwInstall) + { + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"SP", 0, 0, (LPBYTE)&dwSP, &dwSize) && 1 == dwSP) + { + StringCchCatW(szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 3.5 Service Pack 1\r\n"); + } + else + { + StringCchCatW(szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 3.5\r\n"); + } + } + RegCloseKey(hkResult); + } + + bool is40ClientDetected = false; + bool is40FullDetected = false; + //¼ì²â HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4.0\Client\Install - 1 + // => .NET Framework 4.0 Client Profile + if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4.0\\Client", 0, KEY_READ, &hkResult)) + { + dwSize = sizeof(dwInstall); + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Install", 0, 0, (LPBYTE)&dwInstall, &dwSize) && 1 == dwInstall) + { + StringCchCatW(szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 4.0 Client Profile\r\n"); + is40ClientDetected = true; + } + RegCloseKey(hkResult); + } + + //¼ì²â HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4.0\Full\Install - 1 + // => .NET Framework 4.0 Full + if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4.0\\Full", 0, KEY_READ, &hkResult)) + { + dwSize = sizeof(dwInstall); + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Install", 0, 0, (LPBYTE)&dwInstall, &dwSize) && 1 == dwInstall) + { + StringCchCatW(szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 4.0 Full\r\n"); + is40FullDetected = true; + } + RegCloseKey(hkResult); + } + + //¼ì²â HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client\Install - 1 + // switch(HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client\Release) + // => .NET Framework 4.5/4.5.1/4.5.2/4.6/4.6.1 Client Profile + if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Client", 0, KEY_READ, &hkResult)) + { + dwSize = sizeof(dwInstall); + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Install", 0, 0, (LPBYTE)&dwInstall, &dwSize) && 1 == dwInstall) + { + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Release", 0, 0, (LPBYTE)&dwRelease, &dwSize)) + { + StringCchCatW(szDotNetFramework, DOTNET_INFO_LENGTH, GetFxVersionGreaterThen4dot5(dwRelease)); + StringCchCatW(szDotNetFramework, DOTNET_INFO_LENGTH, L" Client Profile\r\n"); + } + else if(!is40ClientDetected){ + StringCchCatW(szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 4.0 Client Profile\r\n"); + } + } + RegCloseKey(hkResult); + } + + //¼ì²â HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\Install - 1 + // switch(HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\Release) + // => .NET Framework 4.5/4.5.1/4.5.2/4.6/4.6.1 Full + if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full", 0, KEY_READ, &hkResult)) + { + dwSize = sizeof(dwInstall); + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Install", 0, 0, (LPBYTE)&dwInstall, &dwSize) && 1 == dwInstall) + { + if (ERROR_SUCCESS == RegQueryValueExW(hkResult, L"Release", 0, 0, (LPBYTE)&dwRelease, &dwSize)) + { + StringCchCatW(szDotNetFramework, DOTNET_INFO_LENGTH, GetFxVersionGreaterThen4dot5(dwRelease)); + StringCchCatW(szDotNetFramework, DOTNET_INFO_LENGTH, L" Full\r\n"); + } + else if(!is40FullDetected){ + StringCchCatW(szDotNetFramework, DOTNET_INFO_LENGTH, L".NET Framework 4.0 Full\r\n"); + } + } + RegCloseKey(hkResult); + } + + return szDotNetFramework; +} + + +void main(int argc, wchar_t* argv[]) +{ + wprintf(GetDotNetFramework()); + getchar(); +} diff --git a/SysInfoDetector/SysInfoDetector.vcproj b/SysInfoDetector/SysInfoDetector.vcproj new file mode 100644 index 0000000..fdc6219 --- /dev/null +++ b/SysInfoDetector/SysInfoDetector.vcproj @@ -0,0 +1,215 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SysInfoDetector/stdafx.cpp b/SysInfoDetector/stdafx.cpp new file mode 100644 index 0000000..a27b824 --- /dev/null +++ b/SysInfoDetector/stdafx.cpp @@ -0,0 +1 @@ +#include "stdafx.h" diff --git a/SysInfoDetector/stdafx.h b/SysInfoDetector/stdafx.h new file mode 100644 index 0000000..c05ce74 --- /dev/null +++ b/SysInfoDetector/stdafx.h @@ -0,0 +1,5 @@ +#pragma once + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include +#include