标签:
- private void button1_Click(object sender, EventArgs e)
- {
- try
- {
-
- if (!File.Exists(textBox1.Text.ToString()))
- {
- MessageBox.Show("输入文件不存在!");
- }
- else if (Convert.ToInt32(textBox2.Text) < 1)
- {
- MessageBox.Show("覆盖次数要大于1");
- }
- else
- {
-
- Process da = new Process();
-
- da.StartInfo.FileName = @"C:\WINDOWS\system32\sdelete.exe";
-
-
- da.StartInfo.Arguments = string.Format("-p {0} -q \"{1}\"",
- Convert.ToInt32(textBox2.Text), textBox1.Text.ToString());
-
- da.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
-
- da.StartInfo.UseShellExecute = false;
-
- da.StartInfo.RedirectStandardInput = true;
- da.StartInfo.RedirectStandardOutput = true;
- da.StartInfo.RedirectStandardError = true;
-
- da.StartInfo.CreateNoWindow = true;
-
- da.Start();
-
- string output = da.StandardOutput.ReadToEnd();
-
- da.WaitForExit();
-
-
- if(File.Exists(textBox1.Text.ToString()))
- {
- richTextBox1.AppendText(output);
- }
- }
- }
- catch (Exception msg)
- {
- MessageBox.Show(msg.Message);
- }
- }
但是,虽然已经把sdelete.exe放置于“C:\windows\system32”文件夹下,使用cmd运行才能正确删除,但当通过C#代码调用时总是会显示错误"系统找不到指定文件".这让我万分伤心啊,但同时该方法的不足之处是需要用户放置sdelete程序,因此我需要寻求新的方法实现粉碎文件.
![技术分享](http://img.blog.csdn.net/20140419151517421?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvRWFzdG1vdW50/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
但是代码中所涉及的使用Process的方法还是值得大家学习的,我们还可以通过它实现很多功能,如下:
- Process.Start("IExplore.exe", "http://www.baidu.com/");
- Process.Start("explorer.exe");
- Process.Start("EXCEL.exe");
- Process.Start("cmd.exe");
关于Process的详细用法建议大家阅读下面这篇优秀文章:http://blog.csdn.net/chen_zw/article/details/7896264
下面是调用cmd.exe程序实现ipconfig查看功能,但是当使用"sdelete -p 2 "F:\test.txt""时还是不能运行,我也不知道为什么?不知道怎么访问Sdelete.exe程序,使用管理员权限运行也不行.
- string command = "";
- System.Diagnostics.Process p = new System.Diagnostics.Process();
- p.StartInfo.FileName = "cmd.exe";
- command = "/c" + "ipconfig";
- p.StartInfo.Arguments = command;
- p.StartInfo.UseShellExecute = false;
- p.StartInfo.RedirectStandardInput = true;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.RedirectStandardError = true;
- p.StartInfo.CreateNoWindow = true;
- p.Start();
- string output = p.StandardOutput.ReadToEnd();
- richTextBox1.AppendText(output);
cmd中ipconfig的运行结果如下,但使用sdelete参数就是不行(>.<):
![技术分享](http://img.blog.csdn.net/20140419153413593?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvRWFzdG1vdW50/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
总
版权声明:本文为博主原创文章,未经博主允许不得转载。
数据恢复 2
标签:
原文地址:http://www.cnblogs.com/watchfluture/p/4744039.html