Hello.

I use Linux, and I have no experience in windows. I have to write a C++ program that checks if Java is installed. I have no idea how to check that (there is no directory such /usr/bin ).
I need this for a Java app and I want check utility. Can you give me a example how to check if something is installed in windows.

Thanks in advance,

Jan Birsa

Recommended Answers

All 4 Replies

Look into the functions RegOpenKeyEx, RegQueryValueEx and RegCloseKey. They are used for opening the registry, reading values from the registry and closing it. Refer the MSDN for more details.

An example snippet here.

is there any less complicated way to check this?

Is possible to do this without use of win32 API?

No, for both.

If you need a less complicated way, the only thing you can do is follow the code example and make one for your needs.

And since Registry is windows specific, you need to use W32 API to access the registry. There is no portable or easy way out, as far as my knowledge goes.

Hello.

I use Linux, and I have no experience in windows. I have to write a C++ program that checks if Java is installed. I have no idea how to check that (there is no directory such /usr/bin ).
I need this for a Java app and I want check utility. Can you give me a example how to check if something is installed in windows.

Thanks in advance,

Jan Birsa

I just want to confirm that it is absolutely necessary for you to write a C++ program running in Windows to determine if Java is installed. If it isn't, you could just write a batch file program that uses the "REG QUERY" command to query the registry, and then you'd check the "%ERRORLEVEL%" Global variable to see if the program returned sucessful (which means the key does exist) or not (which means it doesn't). If you weren't aware already, a batch file is similar to a bash script.

Introduction to Batch file programming for Windows:
http://www.docdroppers.org/wiki/index.php?title=Introduction_to_Batch_Programming

For more information regarding the "REG" command, open up a DOS prompt type either of these:

reg /? - this will show you all of the possible reg functions
reg query /? - this will show you how to query the registry


However, if it is necessary that you use C++ then my suggestion is the same as ~S.O.S~'s.

Good luck, LamaBot

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.