/// <summary>
        /// The NetrShareSetInfo method sets the parameters of a shared resource in a ShareList.
        /// </summary>
        /// <param name="ServerName">A string that identifies the server. If this parameter is NULL, the local computer is used.</param>
        /// <param name="NetName">The name of the share to return information for.</param>
        /// <param name="Level">Specifies the information level of the data. This parameter MUST be one of the following values.</param>
        /// <param name="InfoStruct">Its contents are determined by the value of the Level parameter, as shown in the preceding table.
        /// This parameter MUST NOT contain a null value. </param>
        /// <param name="ParmErr">An integer value that receives the index of the first member of the share information 
        /// structure that caused the ERROR_INVALID_PARAMETER error, if it occurs</param>
        /// <returns>The method returns 0x00000000 (NERR_Success) to indicate success; otherwise, it returns a nonzero error code.</returns>
        public uint NetrShareSetInfo(string ServerName, string NetName, SHARE_ENUM_STRUCT_LEVEL Level, SHARE_INFO InfoStruct, ref uint? ParmErr)
        {
            /*
            NET_API_STATUS NetrShareSetInfo(
                [in, string, unique] SRVSVC_HANDLE ServerName,
                [in, string] WCHAR* NetName,
                [in] DWORD Level,
                [in, switch_is(Level)] LPSHARE_INFO ShareInfo,
                [in, out, unique] DWORD* ParmErr
            );
             */

            Int3264[] paramList;
            uint retVal = 0;

            using (SafeIntPtr pServerName = Marshal.StringToHGlobalUni(ServerName),
                pNetName = Marshal.StringToHGlobalUni(NetName),
                pShareInfo = TypeMarshal.ToIntPtr(InfoStruct, Level, null, null),
                pParmErr = TypeMarshal.ToIntPtr(ParmErr))
            {
                paramList = new Int3264[]{
                    pServerName,
                    pNetName,
                    (uint)Level,
                    pShareInfo, // out value
                    pParmErr,
                    IntPtr.Zero // return value
                    };
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)SRVS_OPNUM.NetrShareSetInfo))
                {
                    retVal = outParamList[paramList.Length - 1].ToUInt32();
                    if (retVal == (uint)Win32ErrorCode_32.ERROR_INVALID_PARAMETER)
                    {
                        ParmErr = TypeMarshal.ToNullableStruct<uint>(outParamList[4]);
                    }
                }
            }
            return retVal;
        }
 /// <summary>
 /// The NetrShareGetInfo method retrieves information about a particular shared resource on the server from the ShareList.
 /// </summary>
 /// <param name="ServerName">A string that identifies the server. If this parameter is NULL, the local computer is used.</param>
 /// <param name="NetName">The name of the share to return information for.</param>
 /// <param name="Level">Specifies the information level of the data. This parameter MUST be one of the following values.</param>
 /// <param name="InfoStruct">Its contents are determined by the value of the Level parameter, as shown in the preceding table.</param>
 /// <returns>The method returns 0x00000000 (NERR_Success) to indicate success; otherwise, it returns a nonzero error code.</returns>
 public uint NetrShareGetInfo(string ServerName, string NetName, SHARE_ENUM_STRUCT_LEVEL Level, out SHARE_INFO? InfoStruct)
 {
     /*
     NET_API_STATUS NetrShareGetInfo(
       [in, string, unique] SRVSVC_HANDLE ServerName,
       [in, string] WCHAR* NetName,
       [in] DWORD Level,
       [out, switch_is(Level)] LPSHARE_INFO InfoStruct
     );
      */
     Int3264[] paramList;
     uint retVal = 0;
     InfoStruct = null;
     using (SafeIntPtr pServerName = Marshal.StringToHGlobalUni(ServerName), pNetName = Marshal.StringToHGlobalUni(NetName))
     {
         paramList = new Int3264[]{
             pServerName,
             pNetName,
             (uint)Level,
             IntPtr.Zero, // out value
             IntPtr.Zero // return value
         };
         using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)SRVS_OPNUM.NetrShareGetInfo))
         {
             retVal = outParamList[paramList.Length - 1].ToUInt32();
             if (retVal == (uint)Win32ErrorCode_32.ERROR_SUCCESS)
             {
                 InfoStruct = TypeMarshal.ToStruct<SHARE_INFO>(outParamList[3], Level, null, null);
             }
         }
     }
     return retVal;
 }
 protected void SetShareInfo(string sharePath, SHARE_INFO_502_I shareInfo)
 {
     using (SrvsClient srvsClient = new SrvsClient(TestConfig.Timeout))
     {
         srvsClient.Bind(TestConfig.SutComputerName, TestConfig.AccountCredential, null);
         SHARE_INFO info = new SHARE_INFO { ShareInfo502 = shareInfo };
         uint? parmErr = 0;
         uint retVal = srvsClient.NetrShareSetInfo(@"\\" + TestConfig.SutComputerName, sharePath, SHARE_ENUM_STRUCT_LEVEL.Level502, info, ref parmErr);
         if (retVal != 0)
         {
             BaseTestSite.Assert.Fail("Fail to get share info through MS-SRVS.");
         }
         srvsClient.UnBind();
     }
 }
        /// <summary>
        /// The NetrShareSetInfo method sets the parameters of a shared resource in a ShareList.
        /// </summary>
        /// <param name="ServerName">A string that identifies the server. If this parameter is NULL, the local computer is used.</param>
        /// <param name="NetName">The name of the share to return information for.</param>
        /// <param name="Level">Specifies the information level of the data. This parameter MUST be one of the following values.</param>
        /// <param name="InfoStruct">Its contents are determined by the value of the Level parameter, as shown in the preceding table.
        /// This parameter MUST NOT contain a null value. </param>
        /// <param name="ParmErr">An integer value that receives the index of the first member of the share information
        /// structure that caused the ERROR_INVALID_PARAMETER error, if it occurs</param>
        /// <returns>The method returns 0x00000000 (NERR_Success) to indicate success; otherwise, it returns a nonzero error code.</returns>
        public uint NetrShareSetInfo(string ServerName, string NetName, SHARE_ENUM_STRUCT_LEVEL Level, SHARE_INFO InfoStruct, ref uint?ParmErr)
        {
            /*
             * NET_API_STATUS NetrShareSetInfo(
             *  [in, string, unique] SRVSVC_HANDLE ServerName,
             *  [in, string] WCHAR* NetName,
             *  [in] DWORD Level,
             *  [in, switch_is(Level)] LPSHARE_INFO ShareInfo,
             *  [in, out, unique] DWORD* ParmErr
             * );
             */

            Int3264[] paramList;
            uint      retVal = 0;

            using (SafeIntPtr pServerName = Marshal.StringToHGlobalUni(ServerName),
                   pNetName = Marshal.StringToHGlobalUni(NetName),
                   pShareInfo = TypeMarshal.ToIntPtr(InfoStruct, Level, null, null),
                   pParmErr = TypeMarshal.ToIntPtr(ParmErr))
            {
                paramList = new Int3264[] {
                    pServerName,
                    pNetName,
                    (uint)Level,
                    pShareInfo, // out value
                    pParmErr,
                    IntPtr.Zero // return value
                };
                using (RpceInt3264Collection outParamList = RpceCall(paramList, (ushort)SRVS_OPNUM.NetrShareSetInfo))
                {
                    retVal = outParamList[paramList.Length - 1].ToUInt32();
                    if (retVal == (uint)Win32ErrorCode_32.ERROR_INVALID_PARAMETER)
                    {
                        ParmErr = TypeMarshal.ToNullableStruct <uint>(outParamList[4]);
                    }
                }
            }
            return(retVal);
        }
        protected void SetShareInfo(string sharePath, SHARE_INFO_502_I shareInfo)
        {
            using (SrvsClient srvsClient = new SrvsClient(TestConfig.Timeout))
            {
                ClientSecurityContext securityContext =
                new SspiClientSecurityContext(
                    TestConfig.DefaultSecurityPackage,
                    TestConfig.AccountCredential,
                    Smb2Utility.GetCifsServicePrincipalName(TestConfig.SutComputerName),
                    ClientSecurityContextAttribute.Connection
                        | ClientSecurityContextAttribute.DceStyle
                        | ClientSecurityContextAttribute.Integrity
                        | ClientSecurityContextAttribute.ReplayDetect
                        | ClientSecurityContextAttribute.SequenceDetect
                        | ClientSecurityContextAttribute.UseSessionKey,
                    SecurityTargetDataRepresentation.SecurityNativeDrep);

                srvsClient.Bind(TestConfig.SutComputerName, TestConfig.AccountCredential, securityContext);
                SHARE_INFO info = new SHARE_INFO { ShareInfo502 = shareInfo };
                uint? parmErr = 0;
                uint retVal = srvsClient.NetrShareSetInfo(@"\\" + TestConfig.SutComputerName, sharePath, SHARE_ENUM_STRUCT_LEVEL.Level502, info, ref parmErr);
                if (retVal != 0)
                {
                    BaseTestSite.Assert.Fail("Fail to get share info through MS-SRVS.");
                }
                srvsClient.UnBind();
            }
        }