[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Determine JVM version using C++

Posted on 2004-08-07
4
Medium Priority
?
288 Views
Last Modified: 2010-04-01
Hi,

How do I determine the version number of the currently running JVM using C++ on a Window OS machine?

I have considered accessing jview (either as a dll or as a ShellExecute command to get the version number of the file), but I'm curious to see if there are better solutions.

Any comments, advice or suggestions will be handsomely rewarded. :)

TIA,
S/.
0
Comment
Question by:stitch2802
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 11744004
Spawning "jview.exe /?" gives the version number of the installed JVM. This info can also be obtained using

#include <windows.h>
#include <iostream>
using namespace std;

#pragma comment(lib,"version.lib")

   void reportError()
   {
       LPVOID lpMsgBuf;

       FormatMessage(
           FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
           NULL,
           GetLastError(),
           MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
           (LPTSTR) &lpMsgBuf,
           0,
           NULL );

       cout << (char*)lpMsgBuf << "\n";

       // Free the buffer.
       LocalFree( lpMsgBuf );
   }

   void main( int argc, char *argv[ ], char *envp[ ] )
   {
       cout << "\n";

       if(2 != argc)
       {
           cout << "Syntax: GetVer <File Name>\n";
           return;
       }

       DWORD dwArg;
       DWORD dwInfoSize = GetFileVersionInfoSize(argv[1], &dwArg);

       if(0 == dwInfoSize)
       {
           cout << "No version info available\n";
           reportError();
           return;
       }

       BYTE* lpBuff = new BYTE[dwInfoSize];

       if(!lpBuff)
       {
           cout << "Out of Memory\n";
           return;
       }

       if(0 == GetFileVersionInfo(argv[1], 0, dwInfoSize, lpBuff))
       {
           cout << "Error retrieving version info\n";
           reportError();
           return;
       }

       VS_FIXEDFILEINFO *vInfo;

       UINT uInfoSize;

       if(0 == VerQueryValue(lpBuff, TEXT("\\"),
               (LPVOID*)&vInfo,
               &uInfoSize))
       {
           cout << "Version information not available\n";
           delete lpBuff;
           return;
       }

       if(0 == uInfoSize)
       {
           cout << "Version information not available\n";
           delete lpBuff;
           return;
       }

       cout << argv[1]
           << " Version: "
           << HIWORD(vInfo->dwFileVersionMS) << ","
           << LOWORD(vInfo->dwFileVersionMS) << ","
           << HIWORD(vInfo->dwFileVersionLS) << ","
           << LOWORD(vInfo->dwFileVersionLS) << "\n";

       delete lpBuff;
   }

(original code taken from http://support.microsoft.com/default.aspx?scid=kb;en-us;167597)
0
 

Author Comment

by:stitch2802
ID: 11744925
Hi jkr,

Thanks for answering, but supppose the user has both JVM versions on his/her computer - as in both the Microsoft JVM and the Java VM - won't jview just give me information about the Microsoft JVM and none whatsoever for the Java VM?

I'm trying to figure which version is running as well.

Any advice? :)

TIA,
S/.

0
 
LVL 86

Expert Comment

by:jkr
ID: 11744994
Well, then just grab the version info from all files in queston :o)

(I'm not too familiar with Java and it's VMs, but obtaining the version information is the same for all)
0
 

Author Comment

by:stitch2802
ID: 11744996
Ok, thanks jkr! =)

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question