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(" "); } var result = sb.ToString(); System.IO.File.WriteAllText(@"back1.txt", result, Encoding.UTF8); MessageBox.Show("完成!"); this.Close();