从网上邻居可以看到我的一些文件夹被共享了,但我不知道这个文件夹的实际位置,删除共享就不方便,请问程序怎么实现列出本机共享的文件夹的路径等属性

解决方案 »

  1.   

    using System;
    using System.Management;namespace ConsoleApplication1
    {
    /// <summary>
    /// Class1 的摘要说明。
    /// </summary>
    class Class1
    {
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {
                ManagementObjectSearcher searcher = new 
                    ManagementObjectSearcher("select * from win32_share");
                foreach (ManagementObject share in searcher.Get()) 
                {
                    Console.WriteLine(share["Name"].ToString());        //名称
                    Console.WriteLine(share["Path"].ToString());        //路径
                }
    }
    }
    }
      

  2.   

    注册表中有:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\Shares
      

  3.   

    谢谢两位,方法都不错,分太少了,不好意思了
    wwqna(york)哥们,不知从select * from win32_share还可以得到其它什么属性
      

  4.   

    应该是包括下面这些信息,在msdn中有  uint32 AccessMask;
      boolean AllowMaximum;
      string Caption;
      string Description;
      datetime InstallDate;
      uint32 MaximumAllowed;
      string Name;
      string Path;
      string Status;
      uint32 Type;
    Properties
    The Win32_Share class defines the following properties. AccessMask 
    Data type: uint32
    Access type: Read-onlyList of access rights to the given file or directory held by the user or group on whose behalf the instance is returned. This property is only supported under Windows NT and Windows 2000. On Windows 98 and on Windows NT/Windows 2000 FAT volumes, the FULL_ACCESS value is returned instead, indicating no security has been set on the object.
    Windows 2000, Windows XP:  This property is no longer used due to the expense of calling GetEffectiveRightsFromAcl. You should use the Win32_Share.GetAccessMask method instead. The value of the AccessMask property is set to NULL.
    AllowMaximum 
    Data type: boolean
    Access type: Read-onlyNumber of concurrent users for this resource has been limited. If TRUE, the value in the MaximumAllowed property is ignored.
    Caption 
    Data type: string
    Access type: Read-onlyShort description (one-line string) of the object.
    Description 
    Data type: string
    Access type: Read-onlyDescription of the object.
    InstallDate 
    Data type: datetime
    Access type: Read-onlyObject was installed. This property does not need a value to indicate that the object is installed.
    MaximumAllowed 
    Data type: uint32
    Access type: Read-onlyLimit on the maximum number of users allowed to use this resource concurrently. The value is only valid if the AllowMaximum property is set to FALSE
    Name 
    Data type: string
    Access type: Read-only
    Qualifiers: KeyAlias given to a path set up as a share on a Windows system.Example: "public"
    Path 
    Data type: string
    Access type: Read-onlyLocal path of the Windows share.Example: "C:\Program Files"
    Status 
    Data type: string
    Access type: Read-onlyCurrent status of the object. Various operational and non-operational statuses can be defined. Operational statuses include: "OK", "Degraded", and "Pred Fail" (an element, such as a SMART-enabled hard drive, may be functioning properly but predicting a failure in the near future). Non-operational statuses include: "Error", "Starting", "Stopping", and "Service". The latter, "Service", could apply during mirror-resilvering of a disk, reload of a user permissions list, or other administrative work. Not all such work is on-line, yet the managed element is neither "OK" nor in one of the other states. Values are:"OK"
    "Error"
    "Degraded"
    "Unknown"
    "Pred Fail"
    "Starting"
    "Stopping"
    "Service"
    "Stressed"
    "Nonrecover"
    "Nocontact"
    "LostComm"Type 
    Data type: uint32
    Access type: Read-onlyType of resource being shared. Types include disk drives, print queues, interprocess communications (IPC), and general devices.Value Meaning 
    0 Disk Drive 
    1 Print Queue 
    2 Device 
    3 IPC 
    2147483648 Disk Drive Admin 
    2147483649 Print Queue Admin 
    2147483650 Device Admin 
    2147483651 IPC Admin