有没有办法通过.net框架来确定文件夹是否共享?
Diretory,DirectoryInfo或FileAttributes似乎都没有任何相应的字段.
我忘记提到的一件事是我想检查网络共享.但我会研究WMI的东西.
您可以使用WMI Win32_Share获取所有共享文件夹的列表,并查看您要查找的文件夹是否在它们之间.这是一个可能对您有帮助的片段:
public static ListGetSharedFolders() { List sharedFolders = new List (); // Object to query the WMI Win32_Share API for shared files... ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from win32_share"); ManagementBaseObject outParams; ManagementClass mc = new ManagementClass("Win32_Share"); //for local shares foreach (ManagementObject share in searcher.Get()){ string type = share["Type"].ToString(); if (type == "0") // 0 = DiskDrive (1 = Print Queue, 2 = Device, 3 = IPH) { string name = share["Name"].ToString(); //getting share name string path = share["Path"].ToString(); //getting share path string caption = share["Caption"].ToString(); //getting share description sharedFolders.Add(path); } } return sharedFolders; }
请注意,我在字节上粗暴地从此链接复制粘贴