做windows服务程序的安装程序是不是可以选择启动类型吗?
选择自动的话开机就会执行丫!

解决方案 »

  1.   

    vc中是可以直接创建服务程序的,只需要在新建工程中选择服务程序就可以了。通常我们总是把自己的程序写成普通的app应用,然后在注册表或者启动栏里面加入自己的程序,这样就能够在系统启动的时候自动启动自己的程序,可是着并不是真正的service。下面是一个简单的服务程序的创建方法,可以参考一下:
    http://www.c-sharpcorner.com/2/window_service.asp还有更多,看看这里:
    http://www.c-sharpcorner.com/WindowsServices.asp
      

  2.   

    添加服务安装程序
     using System; 
    using System.Collections; 
    using System.ComponentModel; 
    using System.Configuration.Install; namespace CodeGuru.MyWindowsService 

    /// <summary> 
    /// Summary description for ProjectInstaller. 
    /// </summary> 
    [RunInstaller(true)] 
    public class ProjectInstaller : 
    System.Configuration.Install.Installer 

      private System.ServiceProcess.ServiceProcessInstaller 
    serviceProcessInstaller1; 
      private System.ServiceProcess.ServiceInstaller serviceInstaller1; 
      /// <summary> 
      /// Required designer variable. 
      /// </summary> 
      private System.ComponentModel.Container components = null;   public ProjectInstaller() 
      { 
       // This call is required by the Designer. 
       InitializeComponent();    // TODO: Add any initialization after the InitComponent call 
      }   #region Component Designer generated code 
      /// <summary> 
      /// Required method for Designer support - do not modify 
      /// the contents of this method with the code editor. 
      /// </summary> 
      private void InitializeComponent() 
      { 
       this.serviceProcessInstaller1 = new 
    System.ServiceProcess.ServiceProcessInstaller(); 
       this.serviceInstaller1 = new 
    System.ServiceProcess.ServiceInstaller(); 
       // 
       // serviceProcessInstaller1 
       // 
       this.serviceProcessInstaller1.Account = 
    System.ServiceProcess.ServiceAccount.LocalSystem; 
       this.serviceProcessInstaller1.Password = null; 
       this.serviceProcessInstaller1.Username = null; 
       // 
       // serviceInstaller1 
       // 
       this.serviceInstaller1.ServiceName = "My Sample Service"; 
    //
    //下面设置服务开机自行启动;
    //
       this.serviceInstaller1.StartType = 
    System.ServiceProcess.ServiceStartMode.Automatic; 
       // 
       // ProjectInstaller 
       // 
       this.Installers.AddRange(new 
    System.Configuration.Install.Installer[] 
    {this.serviceProcessInstaller1, this.serviceInstaller1}); 

      #endregion