码迷,mamicode.com
首页 > Windows程序 > 详细

WindowsForms获取服务名称

时间:2019-03-16 19:30:53      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:txt   添加   name   close   ice   build   services   nbsp   new   

  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();

 

WindowsForms获取服务名称

标签:txt   添加   name   close   ice   build   services   nbsp   new   

原文地址:https://www.cnblogs.com/enych/p/10543813.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!