垃圾清理

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;


//使用C#调用BAT文件实现垃圾清理并显示清理结果
//作者:秦元培
//时间:2012年1月12日
//不足:占用线程太久,界面会卡死,出来的信息无法分辨是已经删除了的还是拒绝访问了的
namespace AutoCleanner
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {


            Process pro = new Process();

            pro.StartInfo.FileName = "autocleaner.bat";

            pro.StartInfo.UseShellExecute = false;

            pro.StartInfo.RedirectStandardInput = true;

            pro.StartInfo.RedirectStandardOutput = true;

            pro.StartInfo.RedirectStandardError = true;

            pro.StartInfo.CreateNoWindow = true;

            pro.Start();

            while (pro.WaitForExit(0)==false)
            {
                textBox1.AppendText(pro.StandardOutput.ReadLine() + "\r\n");
            }

            pro.WaitForExit();
         

        }
    }

}

posted @ 2015-10-21 21:56  applekingghfhfhbr  阅读(118)  评论(0编辑  收藏  举报