我在Windows 2000 / XP特别感兴趣,但Vista / 7的将是有趣太(如果不同)。
我正沿着任务的调度每天都在一个批处理文件或等值线的想法。
编辑:对不起,我应该提供更多的信息。 这个问题涉及到10台机器,我手动应用更新。 我不想以编程方式安装的更新,只是找出是否有准备下载/安装使用批处理或脚本(即在系统托盘中的更新盾牌图标是指示此)的更新。 谢谢。
我在Windows 2000 / XP特别感兴趣,但Vista / 7的将是有趣太(如果不同)。
我正沿着任务的调度每天都在一个批处理文件或等值线的想法。
编辑:对不起,我应该提供更多的信息。 这个问题涉及到10台机器,我手动应用更新。 我不想以编程方式安装的更新,只是找出是否有准备下载/安装使用批处理或脚本(即在系统托盘中的更新盾牌图标是指示此)的更新。 谢谢。
你可以使用WUApiLib
:
UpdateSessionClass session = new UpdateSessionClass();
IUpdateSearcher search = session.CreateUpdateSearcher();
ISearchResult result = search.Search("IsInstalled=0 and IsPresent=0 and Type='Software'");
int numberOfUpdates = result.Updates.Count - 1;
Log.Debug("Found " + numberOfUpdates.ToString() + " updates");
UpdateCollection updateCollection = new UpdateCollection();
for (int i = 0; i < numberOfUpdates; i++)
{
IUpdate update = result.Updates[i];
if (update.EulaAccepted == false)
{
update.AcceptEula();
}
updateCollection.Add(update);
}
if (numberOfUpdates > 0)
{
UpdateCollection downloadCollection = new UpdateCollection();
for (int i = 0; i < updateCollection.Count; i++)
{
downloadCollection.Add(updateCollection[i]);
}
UpdateDownloader downloader = session.CreateUpdateDownloader();
downloader.Updates = downloadCollection;
IDownloadResult dlResult = downloader.Download();
if (dlResult.ResultCode == OperationResultCode.orcSucceeded)
{
for (int i = 0; i < downloadCollection.Count; i++)
{
Log.Debug(string.Format("Downloaded {0} with a result of {1}", downloadCollection[i].Title, dlResult.GetUpdateResult(i).ResultCode));
}
UpdateCollection installCollection = new UpdateCollection();
for (int i = 0; i < updateCollection.Count; i++)
{
if (downloadCollection[i].IsDownloaded)
{
installCollection.Add(downloadCollection[i]);
}
}
UpdateInstaller installer = session.CreateUpdateInstaller() as UpdateInstaller;
installer.Updates = installCollection;
IInstallationResult iresult = installer.Install();
if (iresult.ResultCode == OperationResultCode.orcSucceeded)
{
updated = installCollection.Count.ToString() + " updates installed";
for (int i = 0; i < installCollection.Count; i++)
{
Log.Debug(string.Format("Installed {0} with a result of {1}", installCollection[i].Title, iresult.GetUpdateResult(i).ResultCode));
}
if (iresult.RebootRequired == true)
{
ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");
foreach (ManagementObject shutdown in mcWin32.GetInstances())
{
shutdown.Scope.Options.EnablePrivileges = true;
shutdown.InvokeMethod("Reboot", null);
}
}
}
视窗SUS非常适用于网络上的多台机器。
在“最简单”的方式来告诉是安装Windows更新到夜间发生和下载(如果可用),然后把更新盾牌图标在系统托盘中的更新。 只要浏览一下盘,看看图标是否存在。
你也可以设置Windows以每晚检查更新,然后在指定的时间下载并安装它们。
在关于什么mdsindzeleta说 - 要对这个编程可能不是最好的解决办法。 我会使用内置于Windows XP的功能,以下载并安装更新。 我假设Vista中也有类似的功能。
我相信Windows更新使用BITS服务下载。 你可以使用Windows支持工具找到Bitsadmin.exe。 在命令行可以运行bitsadmin.exe /列表,你可以看到BITS作业的状态。 (即下载进度,作业名称,作业状态)
最后, 视窗SUS不是一种选择,所以我使用同一个批处理文件结合下面的ActiveState的ActivePerl (推荐):
perl的-Nle “打印$ _如果检测到M /更新/ I”<C:\ WINDOWS \ windowsupdate.log处
这可能是原油或肮脏,并且在未来有可能打破,但它目前做什么,我需要。
感谢所有的想法。