zoukankan      html  css  js  c++  java
  • 使用C#代码安装 Windows 服务(不使用InstallUtil)

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

    static class Program
    {
        
    /// <summary>
        
    /// 应用程序的主入口点。
        
    /// </summary>
        [STAThread]
        
    static void Main(string[] args)
        {
            
    // 运行服务
            if (args.Length == 0)
            {
                ServiceBase[] ServicesToRun;
                ServicesToRun 
    = new ServiceBase[] { new MyService1() };
                ServiceBase.Run(ServicesToRun);
            }
            
    // 安装服务
            else if (args[0].ToLower() == "/i" || args[0].ToLower() == "-i")
            {
                
    try
                {
                    
    string[] cmdline = { };
                    
    string serviceFileName = System.Reflection.Assembly.GetExecutingAssembly().Location;

                    TransactedInstaller transactedInstaller 
    = new TransactedInstaller();
                    AssemblyInstaller assemblyInstaller 
    = new AssemblyInstaller(serviceFileName, cmdline);
                    transactedInstaller.Installers.Add(assemblyInstaller);
                    transactedInstaller.Install(
    new System.Collections.Hashtable());
                }
                
    catch (Exception ex)
                {
                    
    string msg = ex.Message;
                }
            }
            
    // 删除服务
            else if (args[0].ToLower() == "/u" || args[0].ToLower() == "-u")
            {
                
    try
                {
                    
    string[] cmdline = { };
                    
    string serviceFileName = System.Reflection.Assembly.GetExecutingAssembly().Location;

                    TransactedInstaller transactedInstaller 
    = new TransactedInstaller();
                    AssemblyInstaller assemblyInstaller 
    = new AssemblyInstaller(serviceFileName, cmdline);
                    transactedInstaller.Installers.Add(assemblyInstaller);
                    transactedInstaller.Uninstall(
    null);
                }
                
    catch (Exception ex)
                {
                    
    string msg = ex.Message;
                }
            }
        }
    }
  • 相关阅读:
    动态规划股票购入卖出
    输入两棵二叉树A,B,判断B是不是A的子结构。(ps:我们约定空树不是任意一个树的子结构)
    java模拟死锁
    从上往下打印出二叉树的每个节点,同层节点从左至右打印。
    java 多线程
    把只包含质因子2、3和5的数称作丑数(Ugly Number)。例如6、8都是丑数,但14不是,因为它包含质因子7。 习惯上我们把1当做是第一个丑数。求按从小到大的顺序的第N个丑数。
    目录操作
    获取文字高度以及根据label内容来调整label的高度
    视图抖动动画
    带有背景显示加载中的activity
  • 原文地址:https://www.cnblogs.com/anjou/p/1203290.html
Copyright © 2011-2022 走看看