Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++/CLI
Hi All,
 
I am new to C/C++ more fluent in .net, but basically for a project im trying to do.
i need to create a C++ CLI that can check if the registry key "SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727" exists. i would like to return the value in a boolean (true/false way)
 
i want to create a little cli that will just check if dotnet framework 2 is installed on the target PC.
 
i have no C/C++ experience. i have done bit searching around but had no luck. anyone have any pointers
Posted 11-Apr-13 14:59pm
Comments
lewax00 at 11-Apr-13 22:59pm
   
If it's C++/CLI, then you won't be able to run your application without .NET installed anyways. Unless you compile it for .NET 1.1, you'll be all set if it even runs in the first place.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Easiest way for you would be to use batch script, since you are not so well versed with C/C++
so i would suggest you to copy/paste below lines to notepad, save it as .bat and execute.
 
@ECHO OFF
@reg query "HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727" /v Version
@if %ERRORLEVEL% EQU 0 (echo exists) else (echo not exists)
@PAUSE
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

you can also use this below C/C++ code
 
#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;
	}
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The first link appears to be what you need to know
http://lmgtfy.com/?q=c%2B%2B%2Fcli+regkey[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Thanks for everyones help. heres my solution.
 
#include <stdio.h>
#include <stdlib.h>

#ifdef WIN32
FILE *popen ( const char* command, const char* flags) {return _popen(command,flags);}
int pclose ( FILE* fd) { return _pclose(fd);}
#endif
 
int main(int argc, char* argv[])
{
    char psBuffer[128];
    FILE *iopipe;
 
    if( (iopipe = popen( "reg.exe QUERY \"HKLM\\SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v2.0.50727\" /v Version", "r"", "r" )) == NULL )
        exit( 1 );
 
    while( !feof( iopipe ) )
    {
        if( fgets( psBuffer, 128, iopipe ) != NULL )
            printf( psBuffer );
    }
 
    printf( "\nProcess returned %d\n", pclose( iopipe ) );
    return 0;
}
</stdlib.h></stdio.h>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,142
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 14 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100