/// <summary>
        ///  The NetrLogonControl2Ex method executes windows-specific
        ///  administrative actions that pertain to the Netlogon
        ///  server operation. It is used to query the status and
        ///  control the actions of the Netlogon server. Opnum :
        ///  18 
        /// </summary>
        /// <param name="ServerName">
        ///  The custom RPC binding handle, as specified in section
        ///  .
        /// </param>
        /// <param name="FunctionCode">
        ///  The control operation to be performed; MUST be one of
        ///  the following values. The following restrictions apply
        ///  to the values of the FunctionCode parameter in windows_nt_4_0,
        ///  windows_2000, windows_7, and windows_server_7. There
        ///  are no restrictions in windows_server_2003, windows_vista,
        ///  and windows_server_2008. The following values are not
        ///  supported on windows_nt_4_0:NETLOGON_CONTROL_CHANGE_PASSWORD
        ///  (0x00000009)NETLOGON_CONTROL_TC_VERIFY (0x0000000A)NETLOGON_CONTROL_FORCE_DNS_REG
        ///  (0x0000000B)NETLOGON_CONTROL_QUERY_DNS_REG (0x0000000C)NETLOGON_CONTROL_BACKUP_CHANGE_LOG
        ///  (0x0000FFFC)NETLOGON_CONTROL_TRUNCATE_LOG (0x0000FFFD)NETLOGON_CONTROL_SET_DBFLAG
        ///  (0x0000FFFE)NETLOGON_CONTROL_BREAKPOINT (0x0000FFFF)The
        ///  error ERROR_NOT_SUPPORTED is returned if one of these
        ///  values is used. The following values are not supported
        ///  on windows_2000_server:NETLOGON_CONTROL_TC_VERIFY (0x0000000A)NETLOGON_CONTROL_FORCE_DNS_REG
        ///  (0x0000000B)NETLOGON_CONTROL_QUERY_DNS_REG (0x0000000C)The
        ///  error ERROR_NOT_SUPPORTED is returned if one of these
        ///  values is used. The following values are not supported
        ///  on windows_7 or windows_server_7:NETLOGON_CONTROL_REPLICATE
        ///  (0x00000002)NETLOGON_CONTROL_SYNCHRONIZE (0x00000003)NETLOGON_CONTROL_PDC_REPLICATE
        ///  (0x00000004)NETLOGON_CONTROL_BACKUP_CHANGE_LOG (0x0000FFFC)The
        ///  error ERROR_NOT_SUPPORTED is returned if one of these
        ///  values is used.
        /// </param>
        /// <param name="QueryLevel">
        ///  Information query level requested by the client. The
        ///  buffer returned in the Buffer parameter contains one
        ///  of the following structures, based on the value of
        ///  this field.
        /// </param>
        /// <param name="Data">
        ///  NETLOGON_CONTROL_DATA_INFORMATION structure, as specified
        ///  in section , that contains specific data required by
        ///  the query.
        /// </param>
        /// <param name="Buffer">
        ///  NETLOGON_CONTROL_QUERY_INFORMATION structure, as specified
        ///  in section , that contains the specific query results,
        ///  with a level of verbosity as specified in QueryLevel.
        /// </param>
        public NetApiStatus NetrLogonControl2Ex(
            string ServerName,
            FunctionCode_Values FunctionCode,
            QueryLevel_Values QueryLevel,
            _NETLOGON_CONTROL_DATA_INFORMATION? Data,
            out _NETLOGON_CONTROL_QUERY_INFORMATION? Buffer)
        {
            const ushort opnum = 18;

            byte[] requestStub;
            byte[] responseStub;
            Int3264[] paramList;
            int retVal;

            SafeIntPtr pServerName = Marshal.StringToHGlobalUni(ServerName);
            SafeIntPtr pData = TypeMarshal.ToIntPtr(Data, FunctionCode, null, null);

            paramList = new Int3264[] {
                pServerName,
                (uint)FunctionCode,
                (uint)QueryLevel,
                pData,
                IntPtr.Zero,
                0 // retVal
            };

            requestStub = RpceStubEncoder.ToBytes(
                     RpceStubHelper.GetPlatform(),
                    NrpcRpcStubFormatString.TypeFormatString,
                    new RpceStubExprEval[] { new RpceStubExprEval(logon__NETLOGON_DELTA_USERExprEval_0000) },
                    NrpcRpcStubFormatString.ProcFormatString,
                    NrpcRpcStubFormatString.ProcFormatStringOffsetTable[opnum],
                    true,
                    paramList);

            rpceClientTransport.Call(opnum, requestStub, rpceTimeout, out responseStub);

            using (RpceInt3264Collection outParamList = RpceStubDecoder.ToParamList(
                     RpceStubHelper.GetPlatform(),
                    NrpcRpcStubFormatString.TypeFormatString,
                    new RpceStubExprEval[] { new RpceStubExprEval(logon__NETLOGON_DELTA_USERExprEval_0000) },
                    NrpcRpcStubFormatString.ProcFormatString,
                    NrpcRpcStubFormatString.ProcFormatStringOffsetTable[opnum],
                    true,
                    responseStub,
                    paramList))
            {
                IntPtr pBuffer = outParamList[4];
                Buffer = TypeMarshal.ToNullableStruct<_NETLOGON_CONTROL_QUERY_INFORMATION>(
                    pBuffer,
                    QueryLevel,
                    null,
                    null);

                retVal = outParamList[5].ToInt32();
            }

            pServerName.Dispose();
            pData.Dispose();

            return (NetApiStatus)retVal;
        }
 /// <summary>
 ///  The NetrLogonControl2Ex method executes windows-specific
 ///  administrative actions that pertain to the Netlogon
 ///  server operation. It is used to query the status and
 ///  control the actions of the Netlogon server. Opnum: 18 
 /// </summary>
 /// <param name="serverName">
 ///  The custom RPC binding handle.
 /// </param>
 /// <param name="functionCode">
 ///  The control operation to be performed; MUST be one of
 ///  the following values. The following restrictions apply
 ///  to the values of the FunctionCode parameter in windows_nt_4_0,
 ///  windows_2000, windows_7, and windows_server_7. There
 ///  are no restrictions in windows_server_2003, windows_vista,
 ///  and windows_server_2008. The following values are not
 ///  supported on windows_nt_4_0: NETLOGON_CONTROL_CHANGE_PASSWORD
 ///  (0x00000009) NETLOGON_CONTROL_TC_VERIFY (0x0000000A) NETLOGON_CONTROL_FORCE_DNS_REG
 ///  (0x0000000B) NETLOGON_CONTROL_QUERY_DNS_REG (0x0000000C) NETLOGON_CONTROL_BACKUP_CHANGE_LOG
 ///  (0x0000FFFC) NETLOGON_CONTROL_TRUNCATE_LOG (0x0000FFFD) NETLOGON_CONTROL_SET_DBFLAG
 ///  (0x0000FFFE) NETLOGON_CONTROL_BREAKPOINT (0x0000FFFF).<para/>
 ///  The error ERROR_NOT_SUPPORTED is returned if one of these
 ///  values is used.<para/>
 ///  The following values are not supported
 ///  on windows_2000_server: NETLOGON_CONTROL_TC_VERIFY (0x0000000A) NETLOGON_CONTROL_FORCE_DNS_REG
 ///  (0x0000000B) NETLOGON_CONTROL_QUERY_DNS_REG (0x0000000C).<para/>
 ///  The error ERROR_NOT_SUPPORTED is returned if one of these
 ///  values is used.<para/>
 ///  The following values are not supported
 ///  on windows_7 or windows_server_7: NETLOGON_CONTROL_REPLICATE
 ///  (0x00000002) NETLOGON_CONTROL_SYNCHRONIZE (0x00000003) NETLOGON_CONTROL_PDC_REPLICATE
 ///  (0x00000004) NETLOGON_CONTROL_BACKUP_CHANGE_LOG (0x0000FFFC).<para/>
 ///  The error ERROR_NOT_SUPPORTED is returned if one of these
 ///  values is used.
 /// </param>
 /// <param name="queryLevel">
 ///  Information query level requested by the client. The
 ///  buffer returned in the Buffer parameter contains one
 ///  of the following structures, based on the value of
 ///  this field.
 /// </param>
 /// <param name="data">
 ///  NETLOGON_CONTROL_DATA_INFORMATION structure, 
 ///  that contains specific data required by
 ///  the query.
 /// </param>
 /// <param name="buffer">
 ///  NETLOGON_CONTROL_QUERY_INFORMATION structure, 
 ///  that contains the specific query results,
 ///  with a level of verbosity as specified in QueryLevel.
 /// </param>
 /// <returns>
 /// The method returns 0x00000000 on success; 
 /// otherwise, it returns a nonzero error code.
 /// </returns>
 public NetApiStatus NetrLogonControl2Ex(
     string serverName,
     FunctionCode_Values functionCode,
     QueryLevel_Values queryLevel,
     _NETLOGON_CONTROL_DATA_INFORMATION? data,
     out _NETLOGON_CONTROL_QUERY_INFORMATION? buffer)
 {
     return rpc.NetrLogonControl2Ex(
         serverName,
         functionCode,
         queryLevel,
         data,
         out buffer);
 }
 /// <summary>
 ///  Decodes the request stub, and fills the fields of the class
 /// </summary>
 /// <param name="sessionContext">The session context of the request received</param>
 /// <param name="requestStub">The request stub got from RPCE layer</param>
 internal override void Decode(NrpcServerSessionContext sessionContext, byte[] requestStub)
 {
     using (RpceInt3264Collection outParamList = RpceStubDecoder.ToParamList(
       RpceStubHelper.GetPlatform(),
         NrpcRpcStubFormatString.TypeFormatString,
         new RpceStubExprEval[] {
             new RpceStubExprEval(NrpcRpcAdapter.logon__NETLOGON_DELTA_USERExprEval_0000) },
         NrpcRpcStubFormatString.ProcFormatString,
         NrpcRpcStubFormatString.ProcFormatStringOffsetTable[(int)Opnum],
         false,
         requestStub))
     {
         ServerName = Marshal.PtrToStringUni(outParamList[0]);
         FunctionCode = (FunctionCode_Values)outParamList[1].ToUInt32();
         QueryLevel = (QueryLevel_Values)outParamList[2].ToUInt32();
     }
 }
 /// <summary>
 ///  The NetrLogonControl method is a predecessor to the
 ///  NetrLogonControl2Ex method. 
 ///  All parameters of this method have the same meanings
 ///  as the identically named parameters of the NetrLogonControl2Ex
 ///  method. Opnum: 12 
 /// </summary>
 /// <param name="serverName">
 ///  ServerName parameter.
 /// </param>
 /// <param name="functionCode">
 ///  FunctionCode parameter.
 /// </param>
 /// <param name="queryLevel">
 ///  QueryLevel parameter.
 /// </param>
 /// <param name="buffer">
 ///  Buffer parameter.
 /// </param>
 /// <returns>
 /// The method returns 0x00000000 on success; 
 /// otherwise, it returns a nonzero error code.
 /// </returns>
 public NetApiStatus NetrLogonControl(
     string serverName,
     FunctionCode_Values functionCode,
     QueryLevel_Values queryLevel,
     out _NETLOGON_CONTROL_QUERY_INFORMATION? buffer)
 {
     return rpc.NetrLogonControl(
         serverName,
         (uint)functionCode,
         (uint)queryLevel,
         out buffer);
 }