title: How to set permissions to all users on a new share folder , by c# code?
body: <p>How to set permissions to all users on a new share folder , by c# code?
  this is my code to add share folder:</p>
  
  <pre><code>public static string sharedFolder()
  {
      try
      {
          // create a directory
          Directory.CreateDirectory(@"C:\MyTestShare");
          // Create a ManagementClass object
          ManagementClass managementClass = new ManagementClass("Win32_Share");
          // Create ManagementBaseObjects for in and out parameters
          ManagementBaseObject inParams = managementClass.GetMethodParameters("Create");
          ManagementBaseObject outParams;
          // Set the input parameters
          inParams["Description"] = "My Files Share";
          inParams["Name"] = "My Files Share";
          inParams["Path"] = @"C:\MyTestShare";
          inParams["Type"] = 0x0; // Disk Drive
          // Invoke the method on the ManagementClass object
          //InvokeMethodOptions _invokeMethodOptions=new InvokeMethodOptions.InfiniteTimeout.h
          outParams = managementClass.InvokeMethod("Create", inParams,null);
          setPermissionsToShareFolder(inParams["Path"].ToString());
          // AddDirectorySecurity(inParams["Path"].ToString());
          // Check to see if the method invocation was successful
          if ((uint)(outParams.Properties["ReturnValue"].Value) != 0)
          {
  
              return ("Unable to share directory.");
          }
  
         return ("Able to share directory.");
  
      }
      catch (Exception e)
      {
          throw new Exception(e.Message);
      } 
  }
  </code></pre>