若要定义应用程序管理部署技术安装程序,请使用 类的 Microsoft.ConfigurationManagement.ApplicationManagement.Installer
实例。 新的类实例将定义客户端上用于实际安装应用程序的属性和方法。
Installer 类具有三种抽象方法, (CreateDetectionAction、CreateInstallAction、CreateUninstallAction) 允许安装程序指定在客户端上用于检测、安装和卸载的 Action 对象。
端到端安装程序需要相应的客户端实现才能正常工作。 如何定义客户端处理程序中介绍了客户端实现。
在远程桌面协议 (RDP) 示例项目中,远程桌面协议 (RDP) 需要新的安装程序。 Configuration Manager中未内置对 RDP 的安装支持,因此需要自定义安装程序。
定义自定义安装程序的基本概述
创建 类的
Microsoft.ConfigurationManagement.ApplicationManagement.Installer
自定义实例。重写 Technology 属性并返回特定于该技术的 TechnologyId 字符串。
重写 方法并
Microsoft.ConfigurationManagement.ApplicationManagement.Installer.CreateDetectAction
创建特定于该技术的自定义检测方法。Microsoft.ConfigurationManagement.ApplicationManagement.Installer.CreateInstallAction
重写 方法并创建特定于该技术的自定义安装方法。Microsoft.ConfigurationManagement.ApplicationManagement.Installer.CreateUninstallAction
重写 方法并创建特定于该技术的自定义卸载方法。创建在客户端上安装自定义技术所需的常规属性。
定义自定义安装程序
使用 构造函数创建 类的
Microsoft.ConfigurationManagement.ApplicationManagement.Installer
实例Microsoft.ConfigurationManagement.ApplicationManagement.Installer
。RDP 示例项目中的以下示例演示如何创建自定义类。
// Installer class for a specific technology. The Installer class defines properties and methods used on the client to actually install the application. public class RdpInstaller : Installer
重写 属性
Microsoft.ConfigurationManagement.ApplicationManagement.Installer.Technology
以返回自定义安装程序技术的正确值。RDP 示例项目中的以下示例演示如何重写 Technology 属性。
// RDP Installer Technology string public override string Technology { get { return Common.TechnologyId; } }
在 RDP 示例项目中,InstallerTechnologyId 的字符串参数定义为项目的 Common 类中的常量。
// Internal ID of the technology. public const string TechnologyId = "Rdp";
Microsoft.ConfigurationManagement.ApplicationManagement.Installer.CreateDetectAction
重写 方法并创建特定于自定义技术的自定义操作。RDP 示例项目中的以下示例演示如何重写 CreateDetectAction 方法。
// Creates an Action used for detection. On the client, this sequence is used to validate if the application is installed. public override Action CreateDetectAction() { Action detectionAction = new Action { Provider = Common.TechnologyId }; detectionAction.Arguments.Add(new Argument("Filename", typeof(string), this.Filename)); detectionAction.Arguments.Add(new Argument("InstallFolder", typeof(string), this.InstallFolder)); detectionAction.Arguments.Add(new Argument("FullAddress", typeof(string), this.FullAddress)); detectionAction.Arguments.Add(new Argument("RemoteApplication", typeof(string), this.RemoteApplication)); detectionAction.Arguments.Add(new Argument("RemoteApplicationMode", typeof(bool), false)); return detectionAction; }
Microsoft.ConfigurationManagement.ApplicationManagement.Installer.CreateInstallAction
重写 方法并创建特定于自定义技术的自定义操作。RDP 示例项目中的以下示例演示如何重写 CreateInstallAction 方法。
// Creates an Action used for installation. On the client, this sequence defines the properties needed to install the application. public override Action CreateInstallAction() { Action installationAction = new Action { Provider = Common.TechnologyId }; installationAction.Arguments.Add(new Argument("Filename", typeof(string), this.Filename)); installationAction.Arguments.Add(new Argument("InstallFolder", typeof(string), this.InstallFolder)); installationAction.Arguments.Add(new Argument("FullScreen", typeof(int), (true == this.fullScreen) ? 1 : 0)); installationAction.Arguments.Add(new Argument("DesktopWidth", typeof(int), this.desktopWidth)); installationAction.Arguments.Add(new Argument("DesktopHeight", typeof(int), this.desktopHeight)); installationAction.Arguments.Add(new Argument("AudioMode", typeof(int), (int)this.AudioMode)); installationAction.Arguments.Add(new Argument("FullAddress", typeof(string), this.FullAddress)); installationAction.Arguments.Add(new Argument("RemoteServerName", typeof(string), this.RemoteServerName)); installationAction.Arguments.Add(new Argument("RemoteServerPort", typeof(int), this.RemoteServerPort)); installationAction.Arguments.Add(new Argument("RemoteApplication", typeof(string), this.RemoteApplication)); installationAction.Arguments.Add(new Argument("RemoteApplicationMode", typeof(bool), false)); installationAction.Arguments.Add(new Argument("ConstructRdpOnClient", typeof(bool), this.ConstructRdpOnClient)); installationAction.Arguments.Add(new Argument("KeyboardMode", typeof(int), (int)this.KeyboardMode)); installationAction.Arguments.Add(new Argument("RedirectPrinters", typeof(int), (true == this.RedirectPrinters) ? 1 : 0)); installationAction.Arguments.Add(new Argument("RedirectSmartCards", typeof(int), (true == this.RedirectSmartCards) ? 1 : 0)); installationAction.Arguments.Add(new Argument("Username", typeof(string), this.Username)); // Adds any references to content to the action. if (this.ConstructRdpOnClient == false && this.Contents.Count > 0) { foreach (Content content in this.Contents) { installationAction.Contents.Add(new ContentRef(content)); } } return installationAction; }
Microsoft.ConfigurationManagement.ApplicationManagement.Installer.CreateUninstallAction
重写 方法并创建特定于自定义技术的自定义操作。RDP 示例项目中的以下示例演示如何重写 CreateUninstallAction 方法。
public override Action CreateUninstallAction() { Action uninstallAction = new Action { Provider = Common.TechnologyId }; uninstallAction.Arguments.Add(new Argument("Filename", typeof(string), this.Filename)); uninstallAction.Arguments.Add(new Argument("InstallFolder", typeof(string), this.InstallFolder)); return uninstallAction; }
在客户端上创建用于安装自定义技术的附加属性和方法。
RDP 示例项目中的以下示例演示了如何创建客户端上用于安装 RDP 应用程序的属性和方法。
// Default height for the RDP window. public const int DefaultDesktopHeight = 768; // Default width for the RDP window public const int DefaultDesktopWidth = 1024; // Default storage location for RDP files created using this Installer public const string DefaultInstallFolder = @"%USERPROFILE%\Desktop\Remote Desktop Connections"; private RdpAudioMode audioMode; private bool constructRdpOnClient;private int desktopHeight; private int desktopWidth; private bool fullScreen; private string installFolder; private RdpKeyboardMode keyboardMode; private string filename; private bool redirectPrinters; private bool redirectSmartCards; private string remoteApplication; private string fullAddress; private string remoteServerName; private ushort remoteServerPort; private string username; // Audio mode for the RDP connection. The default is BringToComputer. public RdpAudioMode AudioMode { get { return audioMode; } set { SetProp("AudioMode", ref audioMode, value); } } // If true, the RDP file will be constructed locally on the client. If false, the RDP file will live on the server and will be downloaded as content. [Mandatory] public bool ConstructRdpOnClient { get { return constructRdpOnClient; } set { SetProp("ConstructRdpOnClient", ref constructRdpOnClient, value); } } // Height of the remote desktop window. This setting is ignored if FullScreen = true. [Default(DefaultDesktopHeight)] public int DesktopHeight { get { return desktopHeight; } set { SetProp("DesktopHeight", ref desktopHeight, value); } } // Width of the remote desktop window. This setting is ignored if FullScreen = true. [Default(DefaultDesktopWidth)] public int DesktopWidth { get { return desktopWidth; } set { SetProp("DesktopWidth", ref desktopWidth, value); } } // If true, full screen window will be used. public bool FullScreen { get { return fullScreen; } set { SetProp("FullScreen", ref fullScreen, value); } } // Directory on the client where the RDP file will be stored. This is part of Detection. [Mandatory][Default(DefaultInstallFolder)] public string InstallFolder { get { return installFolder; } set { SetProp("InstallFolder", ref installFolder, value); } } // Keyboard mode to use for the RDP session. Default is <see cref = "RdpKeyboardMode.FullScreenOnly" /> [Default(RdpKeyboardMode.FullScreenOnly)] public RdpKeyboardMode KeyboardMode { get { return keyboardMode; } set { SetProp("KeyboardMode", ref keyboardMode, value); } } // Name of the RDP profile. This is part of Detection. [Mandatory]public string Filename { get { return filename; } set { SetProp("Filename", ref filename, value); } } // If true, local printers will be redirected to the remote computer. Default is true. [Default(true)]public bool RedirectPrinters { get { return redirectPrinters; } set { SetProp("RedirectPrinters", ref redirectPrinters, value); } } // If true, local smart cards will be redirected to the remote computer. Default is true. [Default(true)] public bool RedirectSmartCards { get { return redirectSmartCards; } set { SetProp("RedirectSmartCards", ref redirectSmartCards, value); } } // Remote application to run. Setting to %WINDIR%\system32\notepad.exe for example will remote only the notepad.exe application. If unspecified, remote shell will be used. Default is unspecified. public string RemoteApplication { get { return remoteApplication; } set { SetProp("RemoteApplication", ref remoteApplication, value); } } // Remote server name for the RDP connection. [MaxLength(254)] public string RemoteServerName { get { return remoteServerName; } set { SetProp("RemoteServerName", ref remoteServerName, value); } } // Remote server port for the RDP connection. Default is 3389. public string FullAddress { get { return fullAddress; } set { SetProp("FullAddress", ref fullAddress, value); } } // Remote server port for the RDP connection. Default is 3389. [Default((ushort)3389)][Range(Min = (ushort)1, Max = (ushort)65534)] public ushort RemoteServerPort { get { return remoteServerPort; } set { SetProp("RemoteServerPort", ref remoteServerPort, value); } } // RDP Installer Technology string public override string Technology { get { return Common.TechnologyId; } } // Username to use for the remote desktop connection. public string Username { get { return username; } set { SetProp("Username", ref username, value); } }
命名空间
Microsoft。ConfigurationManagement.ApplicationManagement
Microsoft。ConfigurationManagement.ApplicationManagement.Serialization
程序集
Microsoft.ConfigurationManagement.ApplicationManagement.dll