Exportar (0) Imprimir
Expandir Tudo
Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
Tradução
Original

ServiceProcessInstaller Classe

Installs an executable containing classes that extend ServiceBase.Essa classe é chamada por utilitários de instalação, como por exemplo InstallUtil. exe, ao instalar um serviço.

Namespace:  System.ServiceProcess
Assembly:  System.ServiceProcess (em System.ServiceProcess. dll)

public class ServiceProcessInstaller : ComponentInstaller

A classe ServiceProcessInstaller executa trabalho comum a todos os serviços em um arquivo executável.Ele é usado pelo utilitário de instalação para gravar valores no Registro do Windows, associados aos serviços que você deseja instalar.

To install a service, create a project installer class that inherits from Installer, and set the RunInstallerAttribute on the class to true.Within your project, instantiate one ServiceProcessInstaller instance per service application, and one ServiceInstaller instance for each service in the application.Finally, add the ServiceProcessInstaller instance and the ServiceInstaller instances to your project installer class.

When InstallUtil.exe runs, the utility looks for classes in the service assembly with the RunInstallerAttribute set to true.Add classes to the service assembly by adding them to the Installers collection associated with your project installer.If RunInstallerAttribute is false, the install utility ignores the project installer.

For an instance of ServiceProcessInstaller, properties you can modify include specifying that a service application run under an account other than the logged-on user.You can specify a particular Username and Password pair under which the service should run, or you can use Account to specify that the service run under the computer's System account, a local or network service account, or a user account.

ObservaçãoObservação:

Conta do sistema do computador não é o mesmo que a conta de administrador.

Normally, you do not call the methods on ServiceInstaller within your code; they are generally called only by the install utility.The install utility automatically calls the ServiceProcessInstaller.Install and ServiceInstaller.Install methods during the installation process.It backs out failures, if necessary, by calling Rollback (or ServiceInstaller.Rollback) on all previously installed components.

An application's install routine maintains information automatically about the components already installed, using the project installer's Installer.Context.This state information is continuously updated as the ServiceProcessInstaller instance and each ServiceInstaller instance is installed by the utility.Ele geralmente é desnecessário para o seu código modificar essas informações de estado explicitamente.

Instantiating a ServiceProcessInstaller causes the base class constructor, ComponentInstaller, to be called.

The following example creates a project installer called MyProjectInstaller, which inherits from Installer.Presume-se houver um executável de serviço que contém dois serviços, "Hello-World Serviço 1" e "Hello-World serviço 2".Within the constructor for MyProjectInstaller (which would be called by the install utility), ServiceInstaller objects are created for each service, and a ServiceProcessInstaller is created for the executable.For the install utility to recognize MyProjectInstaller as a valid installer, the RunInstallerAttribute attribute is set to true.

Optional properties are set on the process installer and the service installers before the installers are added to the Installers collection.When the install utility accesses MyProjectInstaller, the objects added to the Installers collection through a call to InstallerCollection.Add will be installed in turn.During the processo, the instalador maintains informações do estado indicating which Objects have been installed, SO each objeto can be backed out in TURN in maiúscminúsc of an falha instalação.

Normalmente, você poderia não criar uma instância sua classe de instalador do projeto explicitamente.You would create it and add the RunInstallerAttribute, but the install utility actually calls, and therefore instantiates, the class.

using System;
using System.Collections;
using System.Configuration.Install;
using System.ServiceProcess;
using System.ComponentModel;

[RunInstallerAttribute(true)]
public class MyProjectInstaller: Installer{
   private ServiceInstaller serviceInstaller1;
   private ServiceInstaller serviceInstaller2;
   private ServiceProcessInstaller processInstaller;

   public MyProjectInstaller(){
      // Instantiate installers for process and services.
      processInstaller = new ServiceProcessInstaller();
      serviceInstaller1 = new ServiceInstaller();
      serviceInstaller2 = new ServiceInstaller();

      // The services run under the system account.
      processInstaller.Account = ServiceAccount.LocalSystem;

      // The services are started manually.
      serviceInstaller1.StartType = ServiceStartMode.Manual;
      serviceInstaller2.StartType = ServiceStartMode.Manual;

      // ServiceName must equal those on ServiceBase derived classes.            
      serviceInstaller1.ServiceName = "Hello-World Service 1";
      serviceInstaller2.ServiceName = "Hello-World Service 2";

      // Add installers to collection. Order is not important.
      Installers.Add(serviceInstaller1);
      Installers.Add(serviceInstaller2);
      Installers.Add(processInstaller);
   }
}



import System.*;
import System.Collections.*;
import System.Configuration.Install.*;
import System.ServiceProcess.*;
import System.ComponentModel.*;

/** @attribute RunInstallerAttribute(true)
 */
public class MyProjectInstaller extends Installer
{
    private ServiceInstaller serviceInstaller1;
    private ServiceInstaller serviceInstaller2;
    private ServiceProcessInstaller processInstaller;

    public MyProjectInstaller()
    {
        // Instantiate installers for process and services.
        processInstaller = new ServiceProcessInstaller();
        serviceInstaller1 = new ServiceInstaller();
        serviceInstaller2 = new ServiceInstaller();

        // The services run under the system account.
        processInstaller.set_Account(ServiceAccount.LocalSystem);

        // The services are started manually.
        serviceInstaller1.set_StartType(ServiceStartMode.Manual);
        serviceInstaller2.set_StartType(ServiceStartMode.Manual);

        // ServiceName must equal those on ServiceBase derived classes.            
        serviceInstaller1.set_ServiceName("Hello-World Service 1");
        serviceInstaller2.set_ServiceName("Hello-World Service 2");

        // Add installers to collection. Order is not important.
        get_Installers().Add(serviceInstaller1);
        get_Installers().Add(serviceInstaller2);
        get_Installers().Add(processInstaller);
    } //MyProjectInstaller
} //MyProjectInstaller


Quaisquer membros públicos estático (compartilhados na Visual Basic) desse tipo são Thread seguro. Não há garantia de que qualquer membro de instância seja isento de segmentos.

Contribuições da comunidade

ADICIONAR
A Microsoft está realizando uma pesquisa online para saber sua opinião sobre o site do MSDN. Se você optar por participar, a pesquisa online lhe será apresentada quando você sair do site do MSDN.

Deseja participar?
Mostrar:
© 2015 Microsoft