WindowsForms获取服务名称

  StringBuilder sb = new StringBuilder();
            ServiceController[] services = ServiceController.GetServices(); //需要添加引用程序程序集Serviceprocess

            foreach (ServiceController sController in services)
            {
                //sb.AppendFormat("{0} :{1}",sController.ServiceName,sController.Status);
                sb.AppendFormat("{0}", sController.ServiceName);
                sb.Append("\r\n");
            }
            var result = sb.ToString();
            System.IO.File.WriteAllText(@"back1.txt", result, Encoding.UTF8);
            MessageBox.Show("完成!");
            this.Close();

 

posted @ 2019-03-16 18:56  enych  阅读(248)  评论(0编辑  收藏  举报