Exemplo n.º 1
0
        internal static bool IsMachineDomainController(string machineName)
        {
            const uint SV_TYPE_SERVER         = 0x00000002;
            const uint SV_TYPE_DOMAIN_CTRL    = 0x00000008;
            const uint SV_TYPE_DOMAIN_BAKCTRL = 0x00000010;
            IntPtr     ptrSI = IntPtr.Zero;

            try
            {
                int ret = NetServerGetInfo(machineName, 101, out ptrSI);
                if (ret != 0)
                {
                    throw new System.ComponentModel.Win32Exception(ret);
                }

                SERVER_INFO_101 serverInfo = (SERVER_INFO_101)Marshal.PtrToStructure(ptrSI, typeof(SERVER_INFO_101));

                return((serverInfo.Type & SV_TYPE_SERVER) == SV_TYPE_SERVER &&
                       (serverInfo.Type & (SV_TYPE_DOMAIN_CTRL | SV_TYPE_DOMAIN_BAKCTRL)) != 0);
            }
            finally
            {
                if (ptrSI != IntPtr.Zero)
                {
                    NetApiBufferFree(ptrSI);
                }
            }
        }
Exemplo n.º 2
0
 internal ServerInfo(SERVER_INFO_101 info)
 {
     this.PlatformId   = (PlatformId)info.sv101_platform_id;
     this.Name         = info.sv101_name;
     this.MajorVersion = (int)info.sv101_version_major;
     this.MinorVersion = (int)info.sv101_version_minor;
     this.ServerType   = (ServerTypes)info.sv101_type;
     this.Comment      = info.sv101_comment;
 }
Exemplo n.º 3
0
        public override string GetItemDisplaySummaryInfo(int index)
        {
            SERVER_INFO_101 info = internal_list.Keys[index];

            return(string.Format
                       ("{0}, version {1}.{2}",
                       info.sv101_platform_id,
                       info.GetVersionMajor(),
                       info.sv101_version_minor));
        }
Exemplo n.º 4
0
        public static SERVER_INFO_101[] GetServerInfos_101(string domainName, NetserverEnumType servers_type)
        {
            IntPtr ptBuffer       = IntPtr.Zero;
            int    entryes_readed = 0;
            int    total_entryes  = 0;
            uint   resume_handle  = 0;
            IntPtr pt_one_struct  = IntPtr.Zero;

            try
            {
                int res = WinApiNET.NetServerEnum
                              (IntPtr.Zero,
                              NetserverEnumLevel.LEVEL_101,
                              ref ptBuffer,
                              WinApiNET.MAX_PREFERRED_LENGTH,
                              ref entryes_readed,
                              ref total_entryes,
                              servers_type,
                              domainName,
                              ref resume_handle);
                if (res != WinApiNET.NERR_Success)
                {
                    throw new Win32Exception(res);
                }

                int one_struct_len    = Marshal.SizeOf(typeof(SERVER_INFO_101));
                SERVER_INFO_101[] ret = new SERVER_INFO_101[entryes_readed];
                pt_one_struct = Marshal.AllocHGlobal(one_struct_len);
                for (int i = 0; i < entryes_readed; i++)
                {
                    for (int offset = 0; offset < one_struct_len; offset++)
                    {
                        Marshal.WriteByte
                            (pt_one_struct,
                            offset,
                            Marshal.ReadByte(ptBuffer, i * one_struct_len + offset));
                    }
                    ret[i] = (SERVER_INFO_101)Marshal.PtrToStructure
                                 (pt_one_struct,
                                 typeof(SERVER_INFO_101));
                }
                return(ret);
            }
            finally
            {
                if (ptBuffer != IntPtr.Zero)
                {
                    WinApiNET.NetApiBufferFree(ptBuffer);
                }
                if (pt_one_struct != null)
                {
                    Marshal.FreeHGlobal(pt_one_struct);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Constructor without params is required for XML-serialization.
        /// </summary>
        //public ServerInfo()
        //{
        //}
        public static ServerInfo FromNetApi32(SERVER_INFO_101 info)
        {
            var result = new ServerInfo();

            result.m_Name = info.name;
            result.m_Version.PlatformID = info.platform_id;
            result.m_Version.Major      = info.version_major;
            result.m_Version.Minor      = info.version_minor;
            result.m_Version.Type       = info.type;
            result.m_Comment            = info.comment;
            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Advances the enumerator to the next element of the collection.
        /// </summary>
        /// <returns>
        /// <see langword="true"/> if the enumerator was successfully advanced to the next element;
        /// <see langword="false"/> if the enumerator has passed the end of the collection.
        /// </returns>
        /// <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created.</exception>
        public bool MoveNext()
        {
            bool result = false;

            if (++currentItem < itemCount)
            {
                int             newOffset = serverInfoPtr.ToInt32() + SERVER_INFO_101_SIZE * currentItem;
                SERVER_INFO_101 si        = (SERVER_INFO_101)Marshal.PtrToStructure(new IntPtr(newOffset), typeof(SERVER_INFO_101));
                currentServerName = Marshal.PtrToStringAuto(si.sv101_name);
                result            = true;
            }

            return(result);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets the type of the server.
        /// </summary>
        /// <param name="serverName">Name of the server.</param>
        /// <returns></returns>
        public static int GetServerType(string serverName)
        {
            int    result        = 0;
            IntPtr serverInfoPtr = IntPtr.Zero;
            int    rc            = net.NetServerGetInfo(serverName, 101, ref serverInfoPtr);

            if (rc != 0)
            {
                SERVER_INFO_101 si = (SERVER_INFO_101)Marshal.PtrToStructure(serverInfoPtr, typeof(SERVER_INFO_101));
                result = si.sv101_type;
                net.NetApiBufferFree(serverInfoPtr);
                serverInfoPtr = IntPtr.Zero;
            }

            return(result);
        }
Exemplo n.º 8
0
        private void bwNSE_DoWork(object sender, DoWorkEventArgs e)
        {
            IntPtr res;
            int    n = 0, m = 0;
            int    r = NetServerEnum(null, 101, out res, MAX_PREFERRED_LENGTH, ref n, ref m, SV_101_TYPES.SV_TYPE_WORKSTATION | SV_101_TYPES.SV_TYPE_SERVER | SV_101_TYPES.SV_TYPE_DOMAIN_MASTER, null, IntPtr.Zero);

            if (r == 0)
            {
                List <string> pcs = new List <string>();
                try {
                    for (int x = 0; x < n; x++)
                    {
                        SERVER_INFO_101 pc = (SERVER_INFO_101)Marshal.PtrToStructure(new IntPtr(res.ToInt64() + Marshal.SizeOf(typeof(SERVER_INFO_101)) * x), typeof(SERVER_INFO_101));
                        pcs.Add(pc.sv101_name);
                    }
                    e.Result = pcs;
                }
                finally {
                    NetApiBufferFree(res);
                }
            }
        }
Exemplo n.º 9
0
        public static SERVER_INFO_101 GetServerInfo_101(string server_name)
        {
            IntPtr          buffer = IntPtr.Zero;
            SERVER_INFO_101 ret    = new SERVER_INFO_101();

            try
            {
                int res = WinApiNET.NetServerGetInfo(server_name, NetserverInfoLevel.INFO_101, ref buffer);
                if (res != WinApiNET.NERR_Success)
                {
                    throw new Win32Exception(res);
                }
                ret = (SERVER_INFO_101)Marshal.PtrToStructure(buffer, typeof(SERVER_INFO_101));
            }//end of try
            finally
            {
                if (buffer != IntPtr.Zero)
                {
                    WinApiNET.NetApiBufferFree(buffer);
                }
            }

            return(ret);
        }
 internal ComputerInfo(SERVER_INFO_101 info)
 {
     m_info = info;
 }
Exemplo n.º 11
0
 internal ComputerInfo(SERVER_INFO_101 info)
 {
     m_info = info;
 }
Exemplo n.º 12
0
 internal NetworkComputers(SERVER_INFO_101 info)
 {
     _computerinfo = info;
 }