简体   繁体   中英

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.

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

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)

the "Version" field in the registry seems to say its 9.X when I have 11.X installed, but the "svcVersion" shows the same version that displays in the about box of IE11 so perhaps

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\svcVersion

is a better choice?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM