2015-06-04 76 views
1

在TestComplete中,如何在不查看註冊表的情況下使用JScript獲得Microsoft Office版本(不是Excel或Word)?我想這(使用Shell.Application得到程序文件路徑),但它不工作:如何在TestComplete中使用JScript獲取MS Office版本?

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

我們需要更多的細節。你在運行Javascript的環境是什麼?你到目前爲止嘗試了什麼? – doldt

+0

在TestComplete中使用它。 – vinu

+0

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

回答

0

您可以使用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 
    } 
} 
相關問題