一、用vs2008写的一个程序,程序包含windows服务 打包安装后怎么开机就启动这个服务,启动项已经设置成Automatic,而且也设置了当前机子。
二、安装了这个程序后卸载的时候发生异常,然后就无法删除。请问高手什么原因。
希望有高手回答,那些转来转去的帖子就不用发了,能找的我都试过了。只说自己看法,没有详细步骤的也谢谢你们了,不过对我应该没帮助,望高手回答。

解决方案 »

  1.   

    serviceInstaller1:设置ServiceName,如Service1;设置StartType,如Automatic。
    记录日志,卸载什么错误
      

  2.   

    创建Windows服务新建一个Windows服务项目,系统会自动生成一个Service1.cs
    我们自己需要定义一个操作类,添加一个Operate.cs文件,在该文件中添加操作方法在Service1该类中添加:
            Timer doTimer;
            Operate op1 = new Operate();Timer是用来循环执行Operate.cs文件中操作方法的在OnStart方法中输入:
    //设置循环时间,以及循环执行方法
                int doTimerNum = Convert.ToInt32(RestartMinute) * 60 * 1000;
                doTimer = new Timer(doAutoRestartNetReg, null, 0, doTimerNum);手工建立一个方法,用来被Timer执行:
    private void doAutoRestartNetReg(object values)
            {
                //循环调用方法
                op1.RestartAppPool(AppPoolName, LogType);
            }我们可以给项目中添加不同的操作类
    安装我们需要自定义一个安装。在解决方案中添加一个安装和部署中的安装项目
    解决方案资源管理器中选择该项目,设置相关属性:
    如Title、ProductName、Manufacturer(应用程序或组件制造商的名称,安装时为安装目录)、Author
    然后在解决方案资源管理器中右键点击该项目,视图-自定义操作:
    在安装、提交、回滚、卸载中分别添加“应用程序文件夹”中的主输出来自(上面建立的项目名称)活动项再在解决方案资源管理器中右键点击安装项目,添加-项目输出:
    添加主输出在原项目中添加一个安装程序类,如ProjectInstaller.cs,双击这个安装程序类,设置者两个控件:
    在serviceInstaller1控件属性窗口中设置属性内容,或者在代码中,查看InitializeComponent();方法
    在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.Description = "本服务用于IIS应用程序池自定义操作";
                this.serviceInstaller1.DisplayName = "IISAppPool Service";
                this.serviceInstaller1.ServiceName = "IISAppPoolService";
                this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
                // 
                // ProjectInstaller
                // 
                this.Installers.AddRange(new System.Configuration.Install.Installer[] {
                this.serviceProcessInstaller1,
                this.serviceInstaller1});        }设置描述Description 、显示名称DisplayName 、服务名称ServiceName 
    还有启动类型
    好久没有人给我分了 T_T
      

  3.   

    手动执行 InstallUtil.exe 安装和卸载是正常的吗?你要学会调试,因为代码都在你那,有时候贴出一点点代码是无法判断出来的。另外,在调试的时候可以先注释掉一些代码,看是否还出错,直到找到出错的地方。