zoukankan      html  css  js  c++  java
  • [原]创建windows服务


    1、新建windows服务工程MyService。
    2、完成MyService类中的OnStart和OnStop方法,实现服务的启动与停止。
    注:建议该部分处理内容放在单独的工程中,以后调试windows服务时,可以直接允许那个独立工程而不用通过windows服务。
    例如独立对象使用:public static readonly ServiceProcesser ProcesserInstance = newServcieProcesser.ServiceProcesser();调用时使用:ServcieProcesser.ServiceProcesser.ProcesserInstance.OnStart();

    3、添加安装程序类,在项目上右键->添加->新建项->模板中选择“安装程序类”:MyServiceInstaller.
    4、在构造函数中增加以下内容:

                // 创建ServiceProcessInstaller对象和ServiceInstaller对象
                System.ServiceProcess.ServiceProcessInstaller spInstaller =
                    new System.ServiceProcess.ServiceProcessInstaller();
                System.ServiceProcess.ServiceInstaller sInstaller =
                    new System.ServiceProcess.ServiceInstaller();

                // 设定ServiceProcessInstaller对象的帐号、用户名和密码等信息
                spInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
                //this.spInstaller.Username = null;
                //this.spInstaller.Password = null;

                // 设定服务名称
                sInstaller.ServiceName = "MyService";
                sInstaller.Description = "***服务名称";

                // 设定服务的启动方式
                sInstaller.StartType = System.ServiceProcess.ServiceStartMode.Automatic;

                Installers.AddRange(
                    new System.Configuration.Install.Installer[] { spInstaller, sInstaller });
    5、生成工程,完成服务工程。
    6、通过批处理安装:bat文件中写如下内容。
    installutil FaisEtuService.exe
    通过批处理卸载:bat文件中:
    installutil /u FaisEtuService.exe
    【注】:InstallUtil.exe,InstallUtilLib.dll

  • 相关阅读:
    urllib使用四--urlencode,urlparse,
    urllib使用三--urlretrieve下载文件
    urllib使用二
    urllib使用一
    python使用网易邮箱发邮件
    python QQ邮件发送邮件
    可以字符串string转化成list,tuple,dict的eval()方法
    一行代码将两个列表拼接出第三个列表(两个可迭代对象相加产生第三个可迭代对象)--map()方法
    把列表中的元素拼接成字符串
    Runtime 类
  • 原文地址:https://www.cnblogs.com/xinyuxin912/p/1428856.html
Copyright © 2011-2022 走看看