2012-09-26 43 views
0

我已經安裝了Microsoft Office 2010的位置是
「C:\ Program Files文件(x86)的\微軟的Visual Studio 10.0 \ Visual Studio工具用於Office \ PIA \ OFFICE14」
我需要從這個位置動態加載程序集。
是否有可能以編程方式獲取位置「C:\ Program Files(x86)\ Microsoft Visual Studio 10.0 \ Visual Studio Tools for Office \ PIA \ Office14」?編程方式獲得微軟office PIA的位置

+0

如何將路徑保存在配置文件或作爲環境變量。 –

+0

@CodeIgnoto,我需要在任何機器中獲取Office PIA的位置。 – sharmila

+0

@CodeIgnoto,你能否請求告訴我如何使用註冊表獲取它? – sharmila

回答

0

據我所知,你需要找到Office的安裝位置。如果是,那麼Windows Management Instrumentation將幫助您。它可以讓你查詢系統像安裝的軟件數據的API,可用資源等

看看這裏的更多信息: Get installed applications in a system

+0

我需要安裝的應用程序的路徑。 – sharmila

+0

WMI可以解決這個問題。 –

2

這裏是WMI查詢檢索安裝path.You將不得不在WMI查詢中的類似子句之後傳遞程序名稱。因爲我不知道程序名稱,所以我使用了一個類似的子句。如果知道確切的程序名稱,請將其與「=」運算符一起使用。

添加對DLL(System.Management)的引用。

Using System.Management 

    ManagementObjectSearcher WMIQuery = new ManagementObjectSearcher("SELECT * FROM Win32_Product WHERE CAPTION LIKE \"%office%\" "); 
    ManagementObjectCollection WMIQueryCollection = WMIQuery.Get(); 

    foreach (ManagementObject MO in WMIQueryCollection) 
    { 
     Console.WriteLine("Caption : " + MO["Caption"].ToString()); 
     Console.WriteLine("InstallLocation : " + (MO["InstallLocation"] == null ? " " : MO["InstallLocation"].ToString())); 
    } 

這是MSDN鏈接,它將幫助您開始編寫WMI查詢(WQL)。
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394606(v=vs.85).aspx

+0

上面的代碼給我的錯誤 – sharmila

+0

Count ='MyWMIQueryCollection.Count'拋出類型'System.Management.ManagementException'的異常 – sharmila

+0

foreach循環給出錯誤,如無效類。管理異常unhandeld – sharmila