在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);
您可以使用WMI。查询Win32_Product
类获取已安装的Office产品、产品名称(例如"Microsoft Office Standard 2010")和版本号("14.0.7015.1000")。
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
}
}