2012-11-28 24 views
1

我認爲這將是相當直接的,但我使用PatchInstallation類是Microsoft.Deployment.WindowsInstaller的一部分的問題。確定是否使用Microsoft.Deployment.WindowsInstaller.PatchInstallation安裝補丁

已經獲得了正確的補丁代碼和產品代碼(targetcode),我只是調用IsInstalled屬性,但是引發了ArgumentNullExceptions。

PatchInstallation patchInstallation = new PatchInstallation(patchCode.ToString("B"), productCode.ToString("B")); 
return patchInstallation.IsInstalled; 

異常文本是:

System.ArgumentNullException發生消息=值不能爲空。 參數名:字符串源= mscorlib程序PARAMNAME =字符串
堆棧跟蹤: 在System.Number.StringToNumber(字符串str,的NumberStyles選項,NumberBuffer &數,的NumberFormatInfo信息,布爾 parseDecimal) 在System.Number.ParseInt32(一個String ,的NumberStyles風格的NumberFormatInfo信息) 在Microsoft.Deployment.WindowsInstaller.PatchInstallation.get_State() 在Microsoft.Deployment.WindowsInstaller.PatchInstallation.get_IsInstalled() 的InnerException:

如果任何人有任何想法我」 m做錯了pl緩解讓我知道! 乾杯!

回答

1

在獲得修補程序狀態之前,您必須先選擇上下文。使用接受UserContexts並選擇UserManaged,UserUnmanaged或Machine之一的四參數構造函數。

+0

我已經嘗試過使用傳遞userSid和UserContext的四參數構造函數。我爲userSid傳遞null,並且我嘗試了All,UserManaged,UserUnmanaged和Machine。當訪問IsInstalled屬性時,所有參數都爲空參數。它看起來像構造函數缺少PatchStates的參數。 –

+1

如果用戶上下文不是UserManaged,UserUnmanaged或Machine,則DTF使用不支持獲取修補程序狀態的MSI API函數。但是,DTF會忽略任何數量的錯誤,並返回null。我建議通過DTF調用進行調試,以便直接看到錯誤代碼。 –