–>
Sometimes it is useful to know if the computer running your software
has the one or other version of the Internet Explorer installed. I needed
this routine when writing my own setup program for a piece of work which
used the Active X Webbrowser control and required IE 3.02 or upper. I am
able to start the IE setup program and sent clicking messages to the various
dialog boxes popping up, so the user could click on “Install”, lean back
in his armchair and relax watching the procedure.
Until someone came to install it on a machine running IE 4.0. He had
a bad suprise when calling a help function, the whole machine crashed …
According to Knowledge Base article Q1644539,
I wrote a function that detects any of these MSIE Versions:
Internet Explorer 1.0 (Plus!)
Internet Explorer 2.0
Internet Explorer 3.0
Internet Explorer 3.0 (OSR2)
Internet Explorer 3.01
Internet Explorer 3.02
Internet Explorer 4.0 Platform Preview 1.0 (PP1)
Internet Explorer 4.0 Platform Preview 2.0 (PP2)
Internet Explorer 4.0
Internet Explorer 4.01
Internet Explorer 4.01 Service Pack 1 (SP1)
I know that there are at least three other versions of Internet Explorer
outside: IE 4.05, the IE5.0 beta and the IE 4.x version coming with Windows
98. I’m pretty sure that they have unique version strings in the registry,
so it should be very easy to add their correct detection. By now they should
be interpreted as IE 4.01 SP1, which is the most recent version I handle
here. If you know of any other versions – and how to detect them (e.g.
where are IE 4.02 to 4.04?) feel free to add a comment or source code.
The trick used is to open the registry key HKEY_LOCAL_MACHINE\Software\Microsoft\Internet
Explorer and look at various string values. MS has used more than one entry
for version information, so the code is somewhat nested, but still easy
to understand (I hope so). If you are interested in the full details, please
refer to the Knowledge Base.
You may use this code as implemented here (a function) or – if you don’t
like the global functions – make it a member function of your class needing
the information.
In the header file for the function (or class) definition you need these
definitions:
enum IEVERSION { IE_UNKNOWN= 0, // no IE installed or error while retrieving information IE_10W95 = 1, // Internet Explorer 1.0 (Plus!) IE_20W95, // Internet Explorer 2.0 for Windows 95 IE_20WNT, // Internet Explorer 2.0 for Windows NT IE_30, // Internet Explorer 3.0 - this is the version normally distributed with W95 IE_30OSR2, // Internet Explorer 3.0 - this is the version normally distributed with W95b IE_301, // Internet Explorer 3.01 IE_302, // Internet Explorer 3.02 IE_40PP1, // Internet Explorer 4.0 Platform Preview 1.0 (PP1) IE_40PP2, // Internet Explorer 4.0 Platform Preview 2.0 (PP2) IE_40, // Internet Explorer 4.0 IE_401, // Internet Explorer 4.01 IE_401SP1 // Internet Explorer 4.01 Service Pack 1 (SP1) };
// function declaration for the detection function
IEVERSION IEVersion();
In the source code file, use this:
IEVERSION IEVersion()
{
HKEY hCU; IEVERSION c_nIEVersion = IE_UNKNOWN;// let's open the Registry key for IE
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"Software\\Microsoft\\Internet Explorer",
0,KEY_QUERY_VALUE,
&hCU) == ERROR_SUCCESS)
{
char szIEx[100];
DWORD ulSize=100;if (RegQueryValueEx( hCU, "Version", NULL, NULL, (LPBYTE)szIEx, &ulSize)==ERROR_SUCCESS)
// the "Version" key exists, so it is Internet Explorer 4.x
{
// now detect the subversion, which should be one of the following:
//
// 4.71.544 Internet Explorer 4.0 Platform Preview 1.0 (PP1)
// 4.71.1008.3 Internet Explorer 4.0 Platform Preview 2.0 (PP2)
// 4.71.1712.6 Internet Explorer 4.0
// 4.72.2106.8 Internet Explorer 4.01
// 4.72.3110.8 Internet Explorer 4.01 Service Pack 1 (SP1) CString ver(szIEx), majVer, minVer, buildNo, subNo; // cut the main version number
majVer = ver.Left(ver.Find('.')); ver = ver.Mid(ver.Find('.')+1); // cut the minor version number
minVer = ver.Left(ver.Find('.')); ver = ver.Mid(ver.Find('.')+1);// cut the build number
if (ver.Find('.')==-1)
{
buildNo = ver.Left(ver.Find('.'));
subNo = ver.Mid(ver.Find('.')+1); // sub-build number
}
else
buildNo = ver;if (atoi(majVer)>= 4)
// at least this is the Platform Preview 1
{
c_nIEVersion = IE_40PP1;
if (atoi(majVer) == 4 && atoi(minVer)<71)
// this can only happen if there is an error in the version info string
c_nIEVersion = IE_UNKNOWN;
else if (atoi(minVer)>72 || atoi(majVer)> 4)
// we have encountered the highest checked version of this function
// if you need to implement more versions (the IE 4.05 and IE 5.0 beta are out)
// you can implement more comparisons
c_nIEVersion = IE_401SP1;
else if (atoi(minVer)==72 && atoi(buildNo) >= 2106)
c_nIEVersion = IE_401;
else if (atoi(buildNo) >= 1712)
c_nIEVersion = IE_40;
else if (atoi(buildNo) >= 1008)
c_nIEVersion = IE_40PP2;
else if (atoi(buildNo) >= 544)
c_nIEVersion = IE_40PP1;
else // this can only happen if there is an error in the Version info
c_nIEVersion = IE_UNKNOWN;
}
} // end_if (RegQueryValueEx( hCU, "Version", ...))
else if (RegQueryValueEx(hCU, "Build", NULL, NULL,
(LPBYTE)szIEx, &ulSize)==ERROR_SUCCESS)
{
// the "Build" key exists, so it is Internet Explorer 3.x
// now detect the subversion, which should be one of the following:
//
// 520 Internet Explorer 2.0
// 1155 Internet Explorer 3.0
// 1158 Internet Explorer 3.0 (OSR2)
// 1215 Internet Explorer 3.01
// 1300 Internet Explorer 3.02
//
if (atoi(szIEx) < 520)
c_nIEVersion = IE_UNKNOWN;
else if (atoi(szIEx) < 1155)
c_nIEVersion = IE_20W95;
else if (atoi(szIEx) < 1158)
c_nIEVersion = IE_30;
else if (atoi(szIEx) < 1215)
c_nIEVersion = IE_30OSR2;
else if (atoi(szIEx) < 1300)
c_nIEVersion = IE_301;
else if (atoi(szIEx) >= 1300)
c_nIEVersion = IE_302;
}
else if (RegQueryValueEx(hCU, "IVer", NULL, NULL,
(LPBYTE)szIEx, &ulSize)==ERROR_SUCCESS)
{
// IVer was used in the IE versions before 3.0
if (atoi(szIEx)==100)
c_nIEVersion = IE_10W95;
else if (atoi(szIEx)==102)
c_nIEVersion = IE_20W95;
else if (atoi(szIEx)==101)
c_nIEVersion = IE_20WNT;
}
RegCloseKey(hCU);
}
return c_nIEVersion;
} That's it. If you need to insure you have a machine with IE 3 or upper, just test...
if (IEVersion() < IE_30)
// warning here
else
// it's OK
WM_HAVEALOTOFLUCK
Thomas