1.获取本地共享目录
1 public static List<string> GetSharedFolders() 2 { 3 4 var sharedFolders = new List<string>(); 5 6 // Object to query the WMI Win32_Share API for shared files... 7 8 var searcher = new ManagementObjectSearcher("select * from win32_share"); 9 10 foreach (ManagementObject share in searcher.Get()) 11 { 12 13 string type = share["Type"].ToString(); 14 15 if (type == "0") // 0 = DiskDrive (1 = Print Queue, 2 = Device, 3 = IPH) 16 { 17 string path = share["Path"].ToString(); //getting share path 18 19 sharedFolders.Add(path); 20 } 21 22 } 23 24 return sharedFolders; 25 26 }
时间: 2024-10-29 19:06:26