我在程序中用NetShareAdd共享了一个文件夹,现在想在程序执行完以后取消对他的共享应该怎么做?
我想用NetShareDel(null,ref path,0);取消共享,可是不能完成功能?
(注:path是用NetShareAdd共享的文件夹的名字),朋友们帮忙看看是怎么回事?谢谢了

解决方案 »

  1.   

    http://book.77169.com/ask24/how164781.htm
      

  2.   

    做这些事情,我选择WMI:
    using System;
    using System.Management;
    using System.Windows.Forms;namespace WMISample
    {
        public class CallWMIMethod
        {
            public static void Main()
            {
                try
                {
                    ManagementObject classInstance = 
                        new ManagementObject("root\\CIMV2", 
                        "Win32_Share.Name='共享名称'",
                        null);                // no method in-parameters to define
                    // Execute the method and obtain the return values.
                    ManagementBaseObject outParams = 
                        classInstance.InvokeMethod("Delete", null, null);                // List outParams
                    Console.WriteLine("Out parameters:");
                    Console.WriteLine("ReturnValue: " + outParams["ReturnValue"]);
                }
                catch(ManagementException err)
                {
                    MessageBox.Show("An error occurred while trying to execute the WMI method: " + err.Message);
                }
            }
        }
    }
      

  3.   

    using System.Management;
    老大,我的没有这个命名空间,没办法啊
      

  4.   

    你引用一下System.Management就有了啊。
      

  5.   

    就是在引用的的时候在System里面没有Management这个空间,我用的2003,是不是版本太低了呢?
      

  6.   

    跟版本无关的,你有安装.net,就一定会有的。
      

  7.   

    除了代码里要using,解决方案管理器里也要引用的
      

  8.   

    ki1381(史上性价比最高的资深群众)
    谢谢了,终于找到这个命名空间了
    试试jinta2001() 的方法,
      

  9.   

    可否说下怎样用NetShareAdd进行共享?