Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically determine the installed version of IE from a script

We have an automated testing cluster based on selenium-grid.

To manage the cluster, I have built a collection of Rake (Ruby) tasks which can start, restart, ping, and stop nodes. I'm testing our application across a number of browsers including IE6, IE7, and IE8. This means each node in the cluster has to be aware of which version of IE is installed so that it can claim the correct selenium-grid profile name (eg: "IE6 on Windows XP" vs. "IE8 on Windows Vista"), so that certain tests can be written against those browsers.

My question:

I'd like to cut down on the configuration work here. How do I programmatically determine which version of IE is running on the current system? I have tried the following technique:

wmic product where "Vendor like '%Microsoft%'" get Name, Version

But this only returns versions of programs that were installed with the Windows Installer, so IE doesn't show up in this list.

Ideally I'd like to be able to determine this from inside of a Rake script, or at least something that's callable from a Rake script.

like image 507
Maciek Avatar asked Jan 20 '10 21:01

Maciek


2 Answers

You can use WMI, I know it's not a rake script, but you could run the script (or create a .NET application) and feed the results into your application.

It's kind of a hack, but at least it will work. Here's some code from technet.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & _
    "\root\cimv2\Applications\MicrosoftIE")

Set colIESettings = objWMIService.ExecQuery _
    ("Select * from MicrosoftIE_Summary")

For Each strIESetting in colIESettings
    Wscript.Echo strIESetting.Version
Next

Full Source

Once you have this information, you can pass the information to your rake script using the command line.

rake YourScript[<argument from vbscript>]

EDIT: You can copy/paste this code into a file, name it whatever.vbs, and use the cscript command to execute the script.

cscript //Nologo ie_version.vbs

like image 124
Robert Greiner Avatar answered Oct 06 '22 00:10

Robert Greiner


Try this for any version of Windows:

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Internet Explorer"

strValueName = "Version"

oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

Wscript.Echo "Installed IE Version: " & strValue

Wscript.Echo "IE Version: " & Left(strValue,1)
like image 35
Viresh Avatar answered Oct 06 '22 01:10

Viresh