コード例 #1
0
        public static NetRemoteComputerSupportsFeatures GetComputerSupports(string server_name)
        {
            NetRemoteComputerSupportsFeatures wanted    = NetRemoteComputerSupportsFeatures.ANY;
            NetRemoteComputerSupportsFeatures supported = NetRemoteComputerSupportsFeatures.ANY;

            int res = WinApiNET.NetRemoteComputerSupports(server_name, wanted, ref supported);

            if (res != WinApiNET.NERR_Success)
            {
                throw new Win32Exception(res);
            }

            return(supported);
        }
コード例 #2
0
        private void fill_netserver_page()
        {
            try
            {
                SERVER_INFO_102 serv_info = WinApiNETwrapper.GetServerInfo_102(resource_intern.lpRemoteName);
                textBoxNetserverPlatformId.Text      = serv_info.sv102_platform_id.ToString();
                textBoxNetserverSoftwareType.Text    = IOhelper.NetserverTypeToString(serv_info.sv102_type);
                textBoxPlatformVersion.Text          = string.Format("{0}.{1}", serv_info.GetVersionMajor(), serv_info.sv102_version_minor);
                textBoxNetserverMaxUsers.Text        = serv_info.sv102_users.ToString();
                textBoxNetserverDisconnectTime.Text  = serv_info.sv102_disc.ToString();
                textBoxNetserverAnnounceTime.Text    = serv_info.sv102_announce.ToString();
                textBoxNetserverUsersPerLicense.Text = serv_info.sv102_licenses.ToString();
                textBoxNetserverUserPath.Text        = serv_info.sv102_userpath;
            }
            catch (Exception ex)
            {
                errorProvider1.SetIconAlignment(textBoxNetserverPlatformId, ErrorIconAlignment.MiddleLeft);
                errorProvider1.SetError(textBoxNetserverPlatformId, ex.Message);
            }

            try
            {
                NetRemoteComputerSupportsFeatures features = WinApiNETwrapper.GetComputerSupports(resource_intern.lpRemoteName);
                textBoxNetserverFeatures.Text = features.ToString();
            }
            catch (Exception ex)
            {
                errorProvider1.SetIconAlignment(textBoxNetserverFeatures, ErrorIconAlignment.MiddleLeft);
                errorProvider1.SetError(textBoxNetserverFeatures, ex.Message);
            }

            try
            {
                TIME_OF_DAY_INFO dt = WinApiNETwrapper.GetServerTime(resource_intern.lpRemoteName);
                textBoxNetserverDatetime.Text = string.Format("{0} {1},{2}", dt.GetCurrentDatetime().ToLongDateString(), dt.GetCurrentDatetime().ToLongTimeString(), dt.GetCurrentDatetime().Millisecond);
                textBoxNetserverUptime.Text   = dt.GetUptime().ToString();
            }
            catch (Exception ex)
            {
                errorProvider1.SetIconAlignment(textBoxNetserverDatetime, ErrorIconAlignment.MiddleLeft);
                errorProvider1.SetError(textBoxNetserverDatetime, ex.Message);
            }

            //NET_DISPLAY_GROUP[] groups = WinApiNETwrapper.QueryDisplayInfoGroup(resource_intern.lpRemoteName);
            //NET_DISPLAY_MACHINE[] machines = WinApiNETwrapper.QueryDisplayInfoMachine(resource_intern.lpRemoteName);
            //NET_DISPLAY_USER[] users = WinApiNETwrapper.QueryDisplayInfoUser(resource_intern.lpRemoteName);

            try
            {
                SERVER_TRANSPORT_INFO_1[] transports = WinApiNETwrapper.ServerTransportEnum_1(resource_intern.lpRemoteName);
                for (int i = 0; i < transports.Length; i++)
                {
                    ListViewItem lvi = new ListViewItem();
                    lvi.Text = transports[i].svti1_transportname;
                    lvi.SubItems.Add(transports[i].TransportAddress);
                    lvi.SubItems.Add(transports[i].svti1_networkaddress);
                    lvi.SubItems.Add(transports[i].svti1_domain);
                    lvi.SubItems.Add(transports[i].svti1_numberofvcs.ToString());
                    listViewTransports.Items.Add(lvi);
                }
                listViewTransports.Dock = DockStyle.Fill;
            }
            catch (Exception ex)
            {
                errorProvider1.SetIconAlignment(listViewTransports, ErrorIconAlignment.MiddleLeft);
                errorProvider1.SetError(listViewTransports, ex.Message);
            }

            /* net sessions */
            errorProvider1.SetIconAlignment(listViewSessions, ErrorIconAlignment.MiddleLeft);
            Array sessions = null;
            NetSessionEnumLevel session_level = NetSessionEnumLevel.INFO_502;

            try
            {
                //try level 502
                sessions = WinApiNETwrapper.NetSessionEnum(resource_intern.lpRemoteName, null, null, session_level);
            }
            catch (Exception)
            {
                //if exception try level 10
                session_level = NetSessionEnumLevel.INFO_10;
                try
                {
                    sessions = WinApiNETwrapper.NetSessionEnum(resource_intern.lpRemoteName, null, null, session_level);
                }
                catch (Exception ex_10)
                {
                    errorProvider1.SetError(listViewSessions, ex_10.Message);
                }
            }
            if (sessions != null)
            {
                listViewSessions.Dock = DockStyle.Fill;
                for (int i = 0; i < sessions.Length; i++)
                {
                    ListViewItem lvi = new ListViewItem();
                    switch (session_level)
                    {
                    case NetSessionEnumLevel.INFO_502:
                        SESSION_INFO_502 info_502 = (SESSION_INFO_502)sessions.GetValue(i);
                        lvi.Text = info_502.sesi502_cname;
                        lvi.SubItems.Add(info_502.sesi502_username);
                        lvi.SubItems.Add(info_502.sesi502_num_opens.ToString());
                        lvi.SubItems.Add(info_502.TimeActive.ToString());
                        lvi.SubItems.Add(info_502.TimeIdle.ToString());
                        lvi.SubItems.Add(info_502.sesi502_user_flags.ToString());
                        lvi.SubItems.Add(info_502.sesi502_cltype_name);
                        lvi.SubItems.Add(info_502.sesi502_transport);
                        break;

                    case NetSessionEnumLevel.INFO_10:
                        SESSION_INFO_10 info_10 = (SESSION_INFO_10)sessions.GetValue(i);
                        lvi.Text = info_10.sesi10_cname;
                        lvi.SubItems.Add(string.Empty);
                        lvi.SubItems.Add(string.Empty);
                        lvi.SubItems.Add(info_10.TimeActive.ToString());
                        lvi.SubItems.Add(info_10.TimeIdle.ToString());
                        lvi.SubItems.Add(string.Empty);
                        lvi.SubItems.Add(string.Empty);
                        lvi.SubItems.Add(string.Empty);
                        break;
                    }
                    listViewSessions.Items.Add(lvi);
                }
            }
            /* end of net sessions */

            /* open files */
            try
            {
                Array files = WinApiNETwrapper.NetFileEnum(resource_intern.lpRemoteName, null, null, NetFileEnumLevel.INFO_3);
                listViewFiles.Dock = DockStyle.Fill;
                for (int i = 0; i < files.Length; i++)
                {
                    FILE_INFO_3  f_info = (FILE_INFO_3)files.GetValue(i);
                    ListViewItem lvi    = new ListViewItem();
                    lvi.Text = string.Format("0x{0:X}", f_info.fi3_id);
                    lvi.SubItems.Add(f_info.fi3_permission.ToString());
                    lvi.SubItems.Add(f_info.fi3_num_locks.ToString());
                    lvi.SubItems.Add(f_info.fi3_pathname);
                    lvi.SubItems.Add(f_info.fi3_username);
                    listViewFiles.Items.Add(lvi);
                }
            }
            catch (Exception ex_files)
            {
                errorProvider1.SetIconAlignment(listViewFiles, ErrorIconAlignment.MiddleLeft);
                errorProvider1.SetError(listViewFiles, ex_files.Message);
            }
            /* end of open files */
        }