Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Comments
lewax00 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.

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.

SQL
@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
 
Share this answer
 
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;
	}
}
 
Share this answer
 
The first link appears to be what you need to know
http://lmgtfy.com/?q=c%2B%2B%2Fcli+regkey[^]
 
Share this answer
 
Thanks for everyones help. heres my solution.

C++
#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>
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900