title: How to use Win32API NetShareSetInfo to add shared permission？
body: <pre><code>    public static void NetWorkShareSecurity(string hostName, string shareName)
      {
          IntPtr bufptr = IntPtr.Zero;
          var status = NetShareGetInfo(hostName, shareName, 502, out bufptr);
          int err;
          if (status == NET_API_STATUS.NERR_Success)
          {
              SHARE_INFO_502 shareInfo = (SHARE_INFO_502)Marshal.PtrToStructure(bufptr, typeof(SHARE_INFO_502));
              if (shareInfo.shi502_security_descriptor == IntPtr.Zero)
              {
  
                  shareInfo.shi502_security_descriptor = "How do I define a _SECURITY_DESCRIPTOR structure here?";
                  var stu = NetShareSetInfo(hostName, shareName, 502, ref shareInfo, out uint errParm);
                  Console.WriteLine(errParm);
                  Console.WriteLine(GetWin32ErrorMessage((int)stu));
              }
              NetApiBufferFree(bufptr);
          }
          else
          {
              int errCode = Marshal.GetLastWin32Error();
              Console.WriteLine(errCode.ToString() + ":" + GetWin32ErrorMessage(errCode));
          }
      }
  </code></pre>
  
  <p>I added a shared directory by calling NetShareAdd, but I had a problem calling SetSecurityDescriptorDacl. What's the call procedure for this function? I don't want to use the method provided by the System. Managent namespace. That's too opaque.</p>