Created
May 11, 2017 21:12
-
-
Save mr-aleks/f7d5bdca3d7a8b6bbfc776a52552f482 to your computer and use it in GitHub Desktop.
Check if reg key exists to see if dotnet is installed (C/C++)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <stdio.h> | |
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
//set up our variables and buffers. | |
DWORD dwType = 0; | |
wchar_t szVersion[1024] = {0}; | |
DWORD dwDataSize = 1024; | |
HKEY hkeyDotNetVer = NULL; | |
long lResult = 0; | |
// open the key for reading. | |
lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v2.0.50727", 0, KEY_READ, &hkeyDotNetVer); | |
if(ERROR_SUCCESS == lResult) | |
{ | |
// read the version value | |
lResult = RegQueryValueEx(hkeyDotNetVer, L"Version", NULL, &dwType, (BYTE*)szVersion, &dwDataSize); | |
if(ERROR_SUCCESS == lResult) | |
{ | |
//memcpy(szVersion, lpByteData, dwDataSize); | |
std::wcout << "Dot net Version = " << szVersion << std::endl; | |
return 0; | |
} | |
else | |
{ | |
std::wcout<<"unable to read registry Error Code : "<<GetLastError(); | |
return -1; | |
} | |
} | |
else | |
{ | |
std::wcout<<"unable to read registry Error Code : "<<GetLastError(); | |
return -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment