如何在TestComplete中使用JScript获取MS Office版本?

时间:2015-06-04 09:49:32

标签: ms-office jscript testcomplete

在TestComplete中,如何在不查看注册表的情况下使用JScript获取Microsoft Office版本(不是Excel或Word)?我尝试了这个(使用Shell.Application获取程序文件路径)但它不起作用:

var ProgramFiles = aqEnvironment.GetEnvironmentVariable("ProgramFiles", true);
var MSOffFilePath = ProgramFiles +"\\Microsoft Office\\Office14\\";
var Officeversion = aqFileSystem.GetFileInfo(MSOffFilePath).VersionInfo.FileMajorVersion;
Log.Message(Officeversion);

1 个答案:

答案 0 :(得分:0)

您可以使用WMI。查询Win32_Product类以获取已安装的Office产品,产品名称(例如," Microsoft Office Standard 2010")和版本(" 14.0.7015.1000")。 / p>

var oWMI = GetObject("winmgmts:");

// Find all installed products whose name starts with "Microsoft Office"
// but ignore items like "Microsoft Office Proof (English)"
// or "Microsoft Office Office 64-bit Components 2010"
var colSoft = oWMI.ExecQuery(
  "SELECT * FROM Win32_Product"
  + " WHERE Name LIKE 'Microsoft Office%'"
  + " AND NOT Name LIKE '%(%'"
  + " AND NOT Name LIKE '%Proof%'"
  + " AND NOT Name LIKE '%Components%'"
);

if (colSoft.Count == 0) {
  Log.Message("Microsoft Office is not installed.");
}
else {
  var enumSoft = new Enumerator(colSoft);
  var item, strName;
  for (; !enumSoft.atEnd(); enumSoft.moveNext())
  {
    item = enumSoft.item();
    Log.Message(item.Name);    // Microsoft Office Standard 2010
    Log.Message(item.Version); // 14.0.7015.1000
  }
}