[英]How to programmatically determine the installed version of IE from a script
We have an automated testing cluster based on selenium-grid.我们有一个基于 selenium-grid 的自动化测试集群。
To manage the cluster, I have built a collection of Rake (Ruby) tasks which can start, restart, ping, and stop nodes.为了管理集群,我构建了一组 Rake (Ruby) 任务,这些任务可以启动、重启、ping 和停止节点。 I'm testing our application across a number of browsers including IE6, IE7, and IE8.我正在多个浏览器(包括 IE6、IE7 和 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.这意味着集群中的每个节点都必须知道安装了哪个版本的 IE,以便它可以声明正确的 selenium-grid 配置文件名称(例如: "IE6 on Windows XP"
与"IE8 on Windows Vista"
),因此可以针对这些浏览器编写某些测试。
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?如何以编程方式确定当前系统上运行的是哪个版本的 IE? 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.但这只会返回使用 Windows Installer 安装的程序版本,因此 IE 不会出现在此列表中。
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.理想情况下,我希望能够从 Rake 脚本内部确定这一点,或者至少可以从 Rake 脚本中调用。
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.您可以使用 WMI,我知道它不是 rake 脚本,但您可以运行该脚本(或创建 .NET 应用程序)并将结果提供给您的应用程序。
It's kind of a hack, but at least it will work.这有点像黑客,但至少它会起作用。 Here's some code from technet.这是来自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
Once you have this information, you can pass the information to your rake script using the command line.获得此信息后,您可以使用命令行将信息传递给您的 rake 脚本。
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.编辑:您可以将此代码复制/粘贴到文件中,将其命名为whatever.vbs,然后使用cscript命令执行脚本。
cscript //Nologo ie_version.vbs cscript //Nologo ie_version.vbs
Try this for any version of Windows:在任何版本的 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当我安装了 11.X 时,注册表中的“版本”字段似乎显示为 9.X,但“svcVersion”显示的版本与 IE11 的关于框中显示的版本相同,所以也许
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\svcVersion
is a better choice?是更好的选择吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.