   C# - Removing a share from a directory
  Hi,I am using a ManagementClass in C# to execute the Create method in the Win32_Share class (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_share.asp) , this works fine for sharing a directory. However I don't quite understand the Delete method. You'll notice from the documentation that it takes no arguments, does anyone know how it works? Or does anyone know another way of removing a share from a directory?Thanks   
  Furious,To make the long story short, Delete is an instance method, which means you need to get your hands on the ManagementObject representing the share, and then invoke the delete method on that. Then the share that the management object represents will be killed. I threw together a quick (incomplete and inefficient) wrapper class for Win32_Share, which you may find below, along with a piece of testing code, which seems to work fine.using System;using System.Collections.Generic;using System.Text;using System.Management;namespace SharingTest{    class Win32Share    {   public enum MethodStatus: uint   {  Success = 0, //Success  AccessDenied = 2, //Access denied  UnknownFailure = 8, //Unknown failure  InvalidName = 9, //Invalid name  InvalidLevel = 10, //Invalid level  InvalidParameter = 21, //Invalid parameter  DuplicateShare = 22, //Duplicate share  RedirectedPath = 23, //Redirected path  UnknownDevice = 24, //Unknown device or directory  NetNameNotFound = 25 //Net name not found   }   public enum ShareType: uint   {  DiskDrive = 0x0, //Disk Drive  PrintQueue = 0x1, //Print Queue  Device = 0x2, //Device  IPC = 0x3, //IPC  DiskDriveAdmin = 0x80000000, //Disk Drive Admin  PrintQueueAdmin = 0x80000001, //Print Queue Admin  DeviceAdmin = 0x80000002, //Device Admin  IpcAdmin = 0x80000003 //IPC Admin   }   private ManagementObject mWinShareObject;   private Win32Share(ManagementObject obj) { mWinShareObject = obj; }   #region Wrap Win32_Share properties   public uint AccessMask   {  get { return Convert.ToUInt32(mWinShareObject["AccessMask"]); }   }   public bool AllowMaximum   {  get { return Convert.ToBoolean(mWinShareObject["AllowMaximum"]); }   }   public string Caption   {  get { return Convert.ToString(mWinShareObject["Caption"]); }   }   public string Description   {  get { return Convert.ToString(mWinShareObject["Description"]); }   }   public DateTime InstallDate   {  get { return Convert.ToDateTime(mWinShareObject["InstallDate"]); }   }   public uint MaximumAllowed   {  get { return Convert.ToUInt32(mWinShareObject["MaximumAllowed"]); }   }   public string Name   {  get { return Convert.ToString(mWinShareObject["Name"]); }   }   public string Path   {  get { return Convert.ToString(mWinShareObject["Path"]); }   }   public string Status   {  get { return Convert.ToString(mWinShareObject["Status"]); }   }   public ShareType Type   {  get { return (ShareType)Convert.ToUInt32(mWinShareObject["Type"]); }   }   #endregion   #region Wrap Methods   public MethodStatus Delete()   {  object result = mWinShareObject.InvokeMethod("Delete", new object[] { });  uint r = Convert.ToUInt32(result);  return (MethodStatus)r;   }   public static MethodStatus Create(string path, string name, ShareType type, uint maximumAllowed, string description, string password)   {  ManagementClass mc = new ManagementClass("Win32_Share");  object[] parameters = new object[] { path, name, (uint)type, maximumAllowed, description, password, null };  object result = mc.InvokeMethod("Create", parameters);  uint r = Convert.ToUInt32(result);  return (MethodStatus)r;   }   // TODO: Implement here GetAccessMask and SetShareInfo similarly to the above   #endregion   public static IList<Win32Share> GetAllShares()   {  IList<Win32Share> result = new List<Win32Share>();  ManagementClass mc = new ManagementClass("Win32_Share");  ManagementObjectCollection moc = mc.GetInstances();  foreach (ManagementObject mo in moc)  { Win32Share share = new Win32Share(mo); result.Add(share);  }  return result;   }   public static Win32Share GetNamedShare(string name)   {  // Not a very efficient implementation obviously, but heck... This is sample code. ;)  IList<Win32Share> shares = GetAllShares();  foreach (Win32Share s in shares) if (s.Name == name)return s;  return null;   }    }    class Program    {   static void Main(string[] args)   {  // Create a share first:  Win32Share.MethodStatus result = Win32Share.Create("C:\\temp", "Temp", Win32Share.ShareType.DiskDrive, 10, "My Temp Folder", null);  if (result == Win32Share.MethodStatus.Success)  { Console.WriteLine("Yay, we created a temp share!"); Win32Share tempShare = Win32Share.GetNamedShare("Temp"); Win32Share.MethodStatus deleteResult = tempShare.Delete(); if (deleteResult == Win32Share.MethodStatus.Success) {Console.WriteLine("Yay, we deleted temp share!"); }  }   }    }}