如何修改程序属性
以下示例演示如何在 Configuration Manager 中使用 SMS_Package
和 SMS_Program
类和 属性修改程序。
修改程序属性
设置与 SMS 提供程序的连接。
使用提供的包 ID 和程序名称获取程序实例。
将程序说明属性替换为传入方法的 属性。
保存程序对象和属性。
示例
以下示例方法修改软件分发的程序属性。
有关调用示例代码的信息,请参阅调用Configuration Manager代码片段。
Sub ModifyProgram(connection, existingpackageID, existingProgramNameToModify, newProgramDescription)
' Load the specific program to change (programname is a key value and must be unique). Dim program
Set program = connection.Get("SMS_Program.PackageID='" & existingPackageID & "'" & ",ProgramName='" & existingProgramNameToModify & "'")
' Replace the existing program property (in this case the program description).
program.Description = newProgramDescription
program.Comment = newProgramDescription
' Save the program with the modified properties.
program.Put_
' Output program name.
WScript.echo "Modified program: " & program.ProgramName
End Sub
public void ModifyProgram(WqlConnectionManager connection, string existingPackageID, string existingProgramNameToModify, string newProgramDescription)
{
try
{
// Load the specific program to change (programname is a key value and must be unique).
IResultObject program = connection.GetInstance(@"SMS_Program.PackageID='" + existingPackageID + "',ProgramName='" + existingProgramNameToModify + "'");
// Replace the existing program property (in this case the program description).
program["Description"].StringValue = newProgramDescription;
program["Comment"].StringValue = newProgramDescription;
// Save the program with the modified properties.
program.Put();
// Output program name.
Console.WriteLine("Modified program: " + program["ProgramName"].StringValue);
}
catch (SmsException ex)
{
Console.WriteLine("Failed to modify the program. Error: " + ex.Message);
throw;
}
}
示例方法具有以下参数:
参数 | 类型 | 说明 |
---|---|---|
connection swbemServices |
-管理: WqlConnectionManager - VBScript: SWbemServices |
与 SMS 提供程序的有效连接。 |
existingPackageID |
-管理: String - VBScript: String |
要与之关联的程序的现有包的 ID。 |
existingProgramNameToModify |
-管理: String - VBScript: String |
要修改的程序的名称。 |
newProgramDescription |
-管理: String - VBScript: String |
新程序的说明。 |
编译代码
C# 示例需要:
命名空间
系统警报
Microsoft。ConfigurationManagement.ManagementProvider
Microsoft。ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
mscorlib
可靠编程
有关错误处理的详细信息,请参阅关于Configuration Manager错误。