在 Configuration Manager 中,通过修改站点控制文件设置来配置软件更新点。
配置软件更新点
设置与 SMS 提供程序的连接。
使用 SMS_SCI_SysResUse 类连接到站点控制文件的软件更新点资源部分。
Loop可用属性数组,根据需要进行更改。
将属性更改提交到站点控制文件。
示例
以下示例方法通过使用 SMS_SCI_SysResUse
类来配置各种软件更新点设置,以连接到站点控制文件并更改软件更新点属性。
有关调用示例代码的信息,请参阅调用Configuration Manager代码片段。
Sub ConfigureSoftwareUpdatePoint(swbemServices, _
swbemContext, _
siteCode, _
newUseProxy, _
newProxyName, _
newProxyServerPort, _
newAnonymousProxyAccess)
' Load site control file and get software update point section.
swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Refresh", , , swbemContext
Query = "SELECT * FROM SMS_SCI_SysResUse " & _
"WHERE RoleName = 'SMS Software Update Point' " & _
"AND SiteCode = '" & siteCode & "'"
Set SCIComponentSet = swbemServices.ExecQuery(Query, ,wbemFlagForwardOnly Or wbemFlagReturnImmediately, swbemContext)
' Only one instance is returned from the query.
For Each SCIComponent In SCIComponentSet
' Display the SUP server name.
wscript.echo "SUP Server: " & SCIComponent.NetworkOSPath
' Loop through the array of embedded SMS_EmbeddedProperty instances.
For Each vProperty In SCIComponent.Props
' Setting: UseProxy.
If vProperty.PropertyName = "UseProxy" Then
wscript.echo " "
wscript.echo vProperty.PropertyName
wscript.echo "Current value " & vProperty.Value
' Modify the value.
vProperty.Value = newUseProxy
wscript.echo "New value " & newUseProxy
End If
' Setting: ProxyName.
If vProperty.PropertyName = "ProxyName" Then
wscript.echo " "
wscript.echo vProperty.PropertyName
wscript.echo "Current value " & vProperty.Value2
' Modify the value.
vProperty.Value2 = newProxyName
wscript.echo "New value " & newProxyName
End If
' Setting: ProxyServerPort.
If vProperty.PropertyName = "ProxyServerPort" Then
wscript.echo " "
wscript.echo vProperty.PropertyName
wscript.echo "Current value " & vProperty.Value
' Modify the value.
vProperty.Value = newProxyServerPort
wscript.echo "New value " & newProxyServerPort
End If
' Setting: AnonymousProxyAccess.
If vProperty.PropertyName = "AnonymousProxyAccess" Then
wscript.echo " "
wscript.echo vProperty.PropertyName
wscript.echo "Current value " & vProperty.Value
' Modify the value.
vProperty.Value = newAnonymousProxyAccess
wscript.echo "New value " & newAnonymousProxyAccess
End If
Next
' Update the component in your copy of the site control file. Get the path
' to the updated object, which could be used later to retrieve the instance.
Set SCICompPath = SCIComponent.Put_(wbemChangeFlagUpdateOnly, swbemContext)
Next
' Commit the change to the actual site control file.
Set InParams = swbemServices.Get("SMS_SiteControlFile").Methods_("CommitSCF").InParameters.SpawnInstance_
InParams.SiteCode = siteCode
swbemServices.ExecMethod "SMS_SiteControlFile", "CommitSCF", InParams, , swbemContext
End Sub
public void ConfigureSoftwareUpdatePoint(WqlConnectionManager connection,
string siteCode,
string SUPServerName,
string newUseProxy,
string newProxyName,
string newProxyServerPort,
string newAnonymousProxyAccess)
{
try
{
IResultObject siteDefinition = connection.GetInstance("SMS_SCI_SysResUse.FileType=2,ItemName='[\"Display=\\\\" + SUPServerName + "\\\"]MSWNET:[\"SMS_SITE=" + siteCode + "\"]\\\\" + SUPServerName + "\\,SMS Software Update Point',ItemType='System Resource Usage',SiteCode='" + siteCode + "'");
foreach (KeyValuePair<string, IResultObject> kvp in siteDefinition.EmbeddedProperties)
{
// Temporary copy of the embedded properties.
Dictionary<string, IResultObject> embeddedProperties = siteDefinition.EmbeddedProperties;
// Setting: UseProxy.
if (kvp.Value.PropertyList["PropertyName"] == "UseProxy")
{
Console.WriteLine();
Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);
Console.WriteLine("Current value: " + embeddedProperties["UseProxy"]["Value"].StringValue);
// Change the value by using the newUseProxy value that is passed in.
embeddedProperties["UseProxy"]["Value"].StringValue = newUseProxy;
Console.WriteLine("New value : " + newUseProxy);
}
// Setting: ProxyName.
if (kvp.Value.PropertyList["PropertyName"] == "ProxyName")
{
Console.WriteLine();
Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);
Console.WriteLine("Current value: " + embeddedProperties["ProxyName"]["Value2"].StringValue);
// Change the value by using the newProxyName value that is passed in.
embeddedProperties["ProxyName"]["Value2"].StringValue = newProxyName;
Console.WriteLine("New value : " + newProxyName);
}
// Setting: ProxyServerPort.
if (kvp.Value.PropertyList["PropertyName"] == "ProxyServerPort")
{
Console.WriteLine();
Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);
Console.WriteLine("Current value: " + embeddedProperties["ProxyServerPort"]["Value"].StringValue);
// Change the value by using the newProxyServerPort value that is passed in.
embeddedProperties["ProxyServerPort"]["Value"].StringValue = newProxyServerPort;
Console.WriteLine("New value : " + newProxyServerPort);
}
// Setting: AnonymousProxyAccess.
if (kvp.Value.PropertyList["PropertyName"] == "AnonymousProxyAccess")
{
Console.WriteLine();
Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);
Console.WriteLine("Current value: " + embeddedProperties["AnonymousProxyAccess"]["Value"].StringValue);
// Change the value by using the newAnonymousProxyAccess value that is passed in.
embeddedProperties["AnonymousProxyAccess"]["Value"].StringValue = newAnonymousProxyAccess;
Console.WriteLine("New value : " + newAnonymousProxyAccess);
}
// Store the settings that have changed.
siteDefinition.EmbeddedProperties = embeddedProperties;
}
// Save the settings.
siteDefinition.Put();
}
catch (SmsException ex)
{
Console.WriteLine("Failed. Error: " + ex.InnerException.Message);
throw;
}
}
示例方法具有以下参数:
参数 | 类型 | 说明 |
---|---|---|
connection |
-管理: WqlConnectionManager - VBScript: SWbemServices |
与 SMS 提供程序的有效连接。 |
swbemContext |
- VBScript: SWbemContext |
有效的上下文对象。 有关详细信息,请参阅如何使用 WMI 添加Configuration Manager上下文限定符。 |
siteCode |
-管理: String - VBScript: String |
站点代码。 |
SUPServerName |
-管理: String |
软件更新点服务器的名称。 |
newUseProxy |
-管理: String - VBScript: String |
确定是否使用代理服务器。 可能的值: “0” = false “1” = true |
newProxyName |
-管理: String - VBScript: String |
代理服务器名称。 |
newProxyServerPort |
-管理: String - VBScript: String |
代理服务器端口。 |
newAnonymousProxyAccess |
-管理: String - VBScript: String |
确定是否使用凭据连接到代理服务器。 如果此值设置为 true,则需要在 Configuration Manager 2007 管理员控制台中设置用于连接的帐户。 可能的值: “0” = true “1” = false |
编译代码
此 C# 示例需要:
命名空间
System
System.Collections.Generic
System.Text
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
可靠编程
有关错误处理的详细信息,请参阅关于Configuration Manager错误。
.NET Framework 安全性
有关保护Configuration Manager应用程序的详细信息,请参阅Configuration Manager基于角色的管理。
另请参阅
关于软件汇报安装和配置关于Configuration Manager站点控制文件如何使用托管代码读取和写入Configuration Manager站点控制文件如何通过 读取和写入Configuration Manager站点控制文件使用 WMISMS_SCI_Component服务器 WMI 类如何使用 WMI 添加Configuration Manager上下文限定符