• 删除共享文件夹的一小段程序


    这几天在局域网里面总是中毒,共享文件夹里面给人加入了许多熊猫,将共享文件夹删掉吧。写了个写程序完成这个功能

    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 窗体设计器生成的代码

            
    /// <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;
        }

    }

  • 相关阅读:
    typescript tsc : 无法加载文件 E:\nodejs\node_global\tsc.ps1
    windows 无法删除文件
    五、activemq 事务和签收
    六、activemq的broker
    四、activemq 消息持久化
    全球健康药物研发中心郭晋疆:多元科学计算系统在药物研发管线中的搭建与实践
    阿里云携手卫宁健康发布WinCloud智慧医疗云联合解决方案,打造新一代智慧医疗系统
    阿里云林小平:如何实现应用的持续发布?
    科普达人丨一图看懂块存储&云盘
    阿里云无影发布生态共荣计划,携手伙伴推动终端算力上云
  • 原文地址:https://www.cnblogs.com/jillzhang/p/644750.html
Copyright © 2020-2023  润新知