C# 使用C与Windows Update交互
是否有任何API可用于编写与Windows update交互的C程序,并使用它选择性地安装某些更新 我正在考虑将一个列表存储在批准更新的中央存储库中。然后,必须安装一次的客户端应用程序将与Windows Update交互以确定可用的更新,然后安装已批准列表中的更新。这样,更新仍然会从客户端的角度自动应用,但我可以选择应用哪些更新C# 使用C与Windows Update交互,c#,windows-update,C#,Windows Update,是否有任何API可用于编写与Windows update交互的C程序,并使用它选择性地安装某些更新 我正在考虑将一个列表存储在批准更新的中央存储库中。然后,必须安装一次的客户端应用程序将与Windows Update交互以确定可用的更新,然后安装已批准列表中的更新。这样,更新仍然会从客户端的角度自动应用,但我可以选择应用哪些更新 顺便说一句,这不是我在公司的职责,我只是想知道是否有windows update的API以及如何使用它。最简单的方法就是使用它。它是免费的,基本上允许您设置自己的本地w
顺便说一句,这不是我在公司的职责,我只是想知道是否有windows update的API以及如何使用它。最简单的方法就是使用它。它是免费的,基本上允许您设置自己的本地windows update服务器,在那里您可以决定哪些更新被批准用于您的计算机。WSUS服务器和客户端都不需要位于域中,尽管这样可以更容易地配置客户端(如果它们位于域中)。如果您有不同的计算机集需要不同的更新集,则也支持此功能
这不仅实现了您的既定目标,而且通过仅从WSUS服务器下载一次更新,还节省了您的总体网络带宽。如果在您的上下文中允许您使用Windows server Update服务,它将允许您访问
从那里,您应该能够做一些好事:将对WUApiLib的引用添加到您的C项目中
using WUApiLib;
protected override void OnLoad(EventArgs e){
base.OnLoad(e);
UpdateSession uSession = new UpdateSession();
IUpdateSearcher uSearcher = uSession.CreateUpdateSearcher();
uSearcher.Online = false;
try {
ISearchResult sResult = uSearcher.Search("IsInstalled=1 And IsHidden=0");
textBox1.Text = "Found " + sResult.Updates.Count + " updates" + Environment.NewLine;
foreach (IUpdate update in sResult.Updates) {
textBox1.AppendText(update.Title + Environment.NewLine);
}
}
catch (Exception ex) {
Console.WriteLine("Something went wrong: " + ex.Message);
}
}
如果您有一个带有文本框的表单,这将为您提供当前安装更新的列表。有关更多文档,请参阅
但是,这将不允许您查找未通过Windows Update分发的KB修补程序。p-L right。我首先尝试了Christoph Grimmer Die方法,但在某些情况下,它不起作用。我猜这是由于不同版本的.net或操作系统架构(32位或64位)造成的。 然后,为了确保我的程序始终获得每个计算机域的Windows Update等待列表,我执行了以下操作: 安装带有WSUS的serveur可能会节省一些internet带宽: 将所有工作站和服务器添加到WSUS服务器 获取SimpleImpersonation库以使用不同的管理权限(可选)运行此程序 仅在开发人员工作站上安装管理控制台组件,然后运行以下程序: 它将在控制台中打印所有带有UpdateInstallationState的Windows更新。已下载
using System;
using Microsoft.UpdateServices.Administration;
using SimpleImpersonation;
namespace MAJSRS_CalendarChecker
{
class WSUS
{
public WSUS()
{
// I use impersonation to use other logon than mine. Remove the following "using" if not needed
using (Impersonation.LogonUser("mydomain.local", "admin_account_wsus", "Password", LogonType.Batch))
{
ComputerTargetScope scope = new ComputerTargetScope();
IUpdateServer server = AdminProxy.GetUpdateServer("wsus_server.mydomain.local", false, 80);
ComputerTargetCollection targets = server.GetComputerTargets(scope);
// Search
targets = server.SearchComputerTargets("any_server_name_or_ip");
// To get only on server FindTarget method
IComputerTarget target = FindTarget(targets, "any_server_name_or_ip");
Console.WriteLine(target.FullDomainName);
IUpdateSummary summary = target.GetUpdateInstallationSummary();
UpdateScope _updateScope = new UpdateScope();
// See in UpdateInstallationStates all other properties criteria
_updateScope.IncludedInstallationStates = UpdateInstallationStates.Downloaded;
UpdateInstallationInfoCollection updatesInfo = target.GetUpdateInstallationInfoPerUpdate(_updateScope);
int updateCount = updatesInfo.Count;
foreach (IUpdateInstallationInfo updateInfo in updatesInfo)
{
Console.WriteLine(updateInfo.GetUpdate().Title);
}
}
}
public IComputerTarget FindTarget(ComputerTargetCollection coll, string computername)
{
foreach (IComputerTarget target in coll)
{
if (target.FullDomainName.Contains(computername.ToLower()))
return target;
}
return null;
}
}
}
您肯定在寻找Windows Update代理API:我不知道有任何C API。但是你是否考虑过帮助你管理企业级的Windows更新?这是面向C和C++的COM接口,所以除非你想给我一个关于如何从C调用COM API的教程,它对我没有帮助。尽管如此,我还是会第一个承认这是我知识的缺失,而不是你的答案。