Hi all,

First off, I'm relatively new to the world of C/C++. I've taken some courses in University years ago and haven't used it much since.

What brings me back is the following dilema I have:

I've built an application using National Instruments LabVIEW (www.ni.com). For those not familiar its a graphical programming language used mostly for customized data acquisition and control applications. A requirement of software built with LabVIEW is that it requires the LabVIEW runtime engine. It comes packed as an installer and it must be installed before the labview created exe can run.

What we'd like to do is put this application on a cd and have it autorun when the user inserts the cd. This works fine if they have the run time engine installed but won't work if its not installed.

So what I was thinking is:
autorun a C created program to detect if the runtime engine is installed (I would have to check for a registry key)
- If it is installed, run my exe
- If not installed, run runtime engine setup,the my exe

Is this hard to do? Anyone tried something like this before? Is this something installshield is designed for? How can I detect if a registry key exists?

Thanks for any help you can provide.


Recommended Answers

All 2 Replies

Greetings lvdude,

Doing this is not hard. There is a simple approach to this.

Understanding that you are talking about Windows, hence the "Registry", it is not hard to check for a key and its existance.

I just wrote an example of how to query a registry key. It may help gear you in the right direction:

#include <windows.h>
#include <stdio.h>

int checkKey(HKEY tree, const char *folder, char *key) {
	long lRet;
	HKEY hKey;
	char temp[150];
	DWORD dwBufLen;

	// Open location
	lRet = RegOpenKeyEx( tree, folder, 0, KEY_QUERY_VALUE, &hKey );
	if (lRet != ERROR_SUCCESS)
		return 0;

	// Get key
	dwBufLen = sizeof(temp);
	lRet = RegQueryValueEx( hKey, key, NULL, NULL, (BYTE*)&temp, &dwBufLen );
	if (lRet != ERROR_SUCCESS)
		return 0;

	printf("Key value: %s\n", temp);

	// Close key
	lRet = RegCloseKey( hKey );
	if (lRet != ERROR_SUCCESS)
		return 0;

	// Got this far, then key exists
	return 1;

int main() {
	printf("Checking for key: HKEY_CURRENT_USER -> Control Panel -> Desktop -> Wallpaper\n");

	if (checkKey(HKEY_CURRENT_USER, "Control Panel\\Desktop", "Wallpaper"))
		printf("Key Exists.\n");
		printf("Key Does Not Exist.\n");

	return 0;

Hope this helps.
The RegQueryValueEx function retrieves the type and data for a specified value name associated with an open registry key.

LONG RegQueryValueEx(
    HKEY hKey,		// handle of key to query

    LPTSTR lpValueName,	// address of name of value to query

    LPDWORD lpReserved,	// reserved

    LPDWORD lpType,	// address of buffer for value type

    LPBYTE lpData,	// address of data buffer

    LPDWORD lpcbData	// address of data buffer size

Or learn more about it here.

There are other functions, though simply doing an MSDN search may pull up further documentation on such functions within the windows header file.

I hope this does help, and if you have any further questions please feel free to ask.

- Stack Overflow

Thanks for the excellent post, I'm sure that will save me allot of time.
I'm in the process of setting up a c++ compiler and re-acquainting myself, then I'll try to get your example working.
One more simple question: How do you run an exe from a C program? I'm thinking theres probably a OPEN or RUN command or such?
BTW, I did a quick search on MSDN to try to find such a function, but didn't get anything helpful. Is there an easy way to look functions up?

Thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.