Is there a way through the .net framework to determine if a folder is shared or not?
Neither Diretory, DirectoryInfo or FileAttributes seem to have any corresponding field.
One thing I forgot to mention was that I want to be checking for network shares. But I'll investigate the WMI stuff.
You can get a list of all the shared folders using the WMI Win32_Share and see if the folder you're looking for is between them. Here's a snippet that might help you with this:
public static List<string> GetSharedFolders()
{
List<string> sharedFolders = new List<string>();
// 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;
}
Please note that I brutally copy-pasted from this link on bytes
You can use WMI Win32_Share. Take a look at:
http://www.gamedev.net/community/forums/topic.asp?topic_id=408923
Shows a sample for querying, creating and deleting shared folders.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With