Skip to content

Instantly share code, notes, and snippets.

@mr-aleks
Created May 11, 2017 21:12
Show Gist options
  • Save mr-aleks/f7d5bdca3d7a8b6bbfc776a52552f482 to your computer and use it in GitHub Desktop.
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++)
#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