Windows服务的开发如果中规中矩的话开发测试安装都十分繁琐,现备忘一个简易的方案。
主要原理也很简单,就是利用Windows自带的服务管理命令sc进行注册,运行。
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Text;
namespace wiffiMinitorSvr
{
static class Program
{
static string excuteCmd(string cmd)
{
Console.WriteLine("will be excute command {0}", cmd);
Process proc = new Process();
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.Arguments = "/c " + cm