取消磁盘共享

Posted on 2019-01-22 15:04  努力成长静待花开  阅读(242)  评论(0编辑  收藏  举报

实现效果:

  

知识运用:

  Process类

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
            myProcess.StartInfo.FileName="cmd.exe";
            myProcess.StartInfo.UseShellExecute = false;
            myProcess.StartInfo.CreateNoWindow = true;
            myProcess.StartInfo.RedirectStandardInput = true;
            myProcess.Start();
            myProcess.StandardInput.WriteLine("net share "+textBox1.Text+"$ /d");
            MessageBox.Show("执行成功!");
        }