这几天在局域网里面总是中毒,共享文件夹里面给人加入了许多熊猫,将共享文件夹删掉吧。写了个写程序完成这个功能
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Diagnostics;

namespace ShareKiller


{

/**//// <summary>
/// Form1 的摘要说明。
/// </summary>
///

public class Form1 : System.Windows.Forms.Form

{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;

/**//// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()

{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}


/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )

{
if( disposing )

{
if (components != null)

{
components.Dispose();
}
}
base.Dispose( disposing );
}


Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码

/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()

{
this.button1 = new System.Windows.Forms.Button();
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(24, 232);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "取消共享";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// listView1
//

this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[]
{
this.columnHeader1,
this.columnHeader2,
this.columnHeader3});
this.listView1.Location = new System.Drawing.Point(16, 16);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(624, 200);
this.listView1.TabIndex = 1;
this.listView1.View = System.Windows.Forms.View.Details;
//
// columnHeader1
//
this.columnHeader1.Text = "共享名";
this.columnHeader1.Width = 120;
//
// columnHeader2
//
this.columnHeader2.Text = "资源";
this.columnHeader2.Width = 250;
//
// columnHeader3
//
this.columnHeader3.Text = "注释";
this.columnHeader3.Width = 250;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(648, 267);
this.Controls.Add(this.listView1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "共享文件夹设置工具";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);

}
#endregion


/**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()

{
Application.Run(new Form1());
}

public static ArrayList GetShareFiles()

{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
string cmdText="net share";
p.StandardInput.WriteLine(cmdText);
p.StandardInput.WriteLine("exit");
string strRst = p.StandardOutput.ReadToEnd();
p.Close();
ArrayList list = new ArrayList();
if(strRst.IndexOf("命令成功完成")!=-1)

{
//成功
string ss="-------------------------------------------------------------------------------";
int index1 = strRst.IndexOf(ss)+ss.Length;
ss="命令成功完成";
int index2 = strRst.IndexOf(ss);
strRst = strRst.Substring(index1,index2-index1);
string[] items = System.Text.RegularExpressions.Regex.Split(strRst,"\r\n",System.Text.RegularExpressions.RegexOptions.IgnoreCase);
foreach(string it in items)

{
if(it!="")

{
string[] sss = it.Split(' ');
int i=0;
ShareInfo si = new ShareInfo();
foreach(string s in sss)

{
if(s!="")

{
if(i==0)

{

si.Name=s;
}
else if(i==1)

{
si.Resource=s;
}
else if(i==2)

{
si.Note = s;
break;
}
i++;
}
}list.Add(si);
}
}
}
return list;
}
public static void Excute(string cmdText)

{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine(cmdText);
p.StandardInput.WriteLine("exit");
while(!p.HasExited)

{
p.WaitForExit();
}
p.Close();
}

void BindData()

{
ArrayList list = GetShareFiles();
listView1.Items.Clear();
foreach(ShareInfo si in list)

{

ListViewItem item = new ListViewItem(new string[]
{si.Name,si.Resource,si.Note});
listView1.Items.Add(item);
}
}
private void Form1_Load(object sender, System.EventArgs e)

{
BindData();
}

private void button1_Click(object sender, System.EventArgs e)

{
foreach(ListViewItem item in listView1.Items)

{
if(item.Selected)

{
string cmdText = "net share "+item.Text+" /delete";
Excute(cmdText);
}
}
BindData();
}
}
public class ShareInfo

{
public string Name;
public string Resource;
public string Note;
}
}
