2013-04-03 15 views
2

是否可以使用WUAPI 2.0類型庫在遠程計算機上查看Windows Update歷史記錄?它必須與Windows XP和Windows 7兼容。從遠程計算機使用WUAPILib檢索Windows Update歷史記錄

可以根據微軟的文章Using WUA From a Remote Computer

「Windows Update代理(WUA)API,可以在遠程計算機上或者是在遠程運行的應用程序用戶使用電腦。」

...但我無法找到解釋如何實際查詢遠程計算機或指定計算機主機名或IP地址的位置。

我使用下面的示例代碼來獲得我從本地機器所需要的信息:

UpdateSession updateSession = new UpdateSession(); 
IUpdateSearcher updateSearcher = updateSession.CreateUpdateSearcher(); 
int count = updateSearcher.GetTotalHistoryCount(); 
IUpdateHistoryEntryCollection history = updateSearcher.QueryHistory(0, count); 
for (int i = 0; i < count; ++i) 
{ 
    Console.WriteLine(string.Format("Title: {0}\tSupportURL: {1}\tDate: {2}\tResult Code: {3}\tDescription: {4}\r\n", history[i].Title, history[i].SupportUrl, history[i].Date, history[i].ResultCode, history[i].Description)); 
}  

是否有可能使用WUAPILib(或類似)給拉了回來相同的信息從上面的代碼遠程機器? WMI類Win32_QuickFixEngineering不提供與WUAPILib相同的信息,因此它不是一個選項,我寧願不必手動挖掘註冊表以提取信息。謝謝!

回答

6

related question的答案基本上回答了我的問題。

下面的修飾的代碼示例現在可以查詢遠程機器:

Type t = Type.GetTypeFromProgID("Microsoft.Update.Session", "remotehostname"); 
UpdateSession session = (UpdateSession)Activator.CreateInstance(t); 
IUpdateSearcher updateSearcher = session.CreateUpdateSearcher(); 
int count = updateSearcher.GetTotalHistoryCount(); 
IUpdateHistoryEntryCollection history = updateSearcher.QueryHistory(0, count); 
for (int i = 0; i < count; ++i) 
{ 
    Console.WriteLine(string.Format("Title: {0}\tSupportURL: {1}\tDate: {2}\tResult Code: {3}\tDescription: {4}\r\n", history[i].Title, history[i].SupportUrl, history[i].Date, history[i].ResultCode, history[i].Description)); 
}