public static ShareReturnCode Delete(string serverName, string shareName) { var query = new WqlObjectQuery("select Name from Win32_Share"); var scope = WmiHelper.Connect(serverName); using (var search = new ManagementObjectSearcher(scope, query)) { foreach (ManagementObject share in search.Get()) { string name = share["Name"].ToString(); if (name.EqualsIgnoreCase(shareName)) { share.Delete(); return(ShareReturnCode.Success); } } } return(ShareReturnCode.UnknownFailure); }
public static string GetLocalPathForShare(string serverName, string shareName) { var query = new WqlObjectQuery("select Name, Path from Win32_Share"); var scope = WmiHelper.Connect(serverName); using (var search = new ManagementObjectSearcher(scope, query)) { foreach (var share in search.Get()) { string name = share["Name"].ToString(); string path = share["Path"].ToString(); if (name.EqualsIgnoreCase(shareName)) { return(path); } } } throw new Exception("There is no share '{0}' on machine '{1}'".FormatWith(shareName, serverName)); }