コード例 #1
0
ファイル: Servicios.cs プロジェクト: chavy25/Task-Manager
        //funcion interna que obtiene el process ID del servicio mediante el DLL
        private ServiciosClass obtenerServicio(string nombreServicio)
        {
            ServiciosClass servicio = new ServiciosClass();

            System.Management.SelectQuery consulta = new System.Management.SelectQuery(string.Format("select processid, startname from Win32_Service where name = '{0}'", nombreServicio));
            System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(consulta);

            foreach (System.Management.ManagementObject servicioController in searcher.Get())
            {
                try
                {
                    servicio.Id = servicioController["PROCESSID"].ToString();
                    servicio.UsuarioServicio = servicioController["STARTNAME"].ToString();
                }
                catch (Exception)
                {
                    servicio.Id = string.Empty;
                    servicio.UsuarioServicio = "Acceso Denegado";
                }
            }
            return(servicio);
        }
コード例 #2
0
ファイル: Servicios.cs プロジェクト: chavy25/Task-Manager
        public void CargarServicios()
        {
            try
            {
                var tablaDatosServ = new DataTable();
                source = new BindingSource();
                //listaServ;// cargo los servicios en el inicio de la creacion del form
                listaServ = (ServiceController[])ServiceController.GetServices();

                tablaDatosServ.Columns.Add("ID");
                tablaDatosServ.Columns.Add("Nombre");
                tablaDatosServ.Columns.Add("Descripcion");
                tablaDatosServ.Columns.Add("Usuario");

                int i = 0;

                foreach (var ser in listaServ)
                {
                    serviciosClass = new ServiciosClass();

                    if (/*listaServ[i].MachineName.ToString()*/ "MAX-MENA".Equals(Environment.MachineName))
                    {
                        serviciosClass.Id     = i.ToString();
                        serviciosClass.Nombre = ser.ServiceName.ToString();
                        serviciosClass.Desc   = ser.ServiceType.ToString();

                        if (listaServ[i].MachineName.ToString().Equals("."))
                        {
                            //serviciosClass.Usuario = listaServ[i].MachineName.ToString();
                            serviciosClass.Usuario = Environment.MachineName.ToString();
                        }
                        else
                        {
                            serviciosClass.Usuario = ser.MachineName.ToString();
                        }
                    }
                    else
                    {
                        serviciosClass.Id      = i.ToString();
                        serviciosClass.Nombre  = "Error";
                        serviciosClass.Desc    = "Error";
                        serviciosClass.Usuario = "Error";
                    }

                    tablaDatosServ.Rows.Add(serviciosClass.Id, serviciosClass.Nombre, serviciosClass.Desc, serviciosClass.Usuario);
                    i++;
                }
                source.DataSource = tablaDatosServ; //ejemplo sin utilizar data source2

                dgvServicios.DataSource = source;   //ejemplo sin el data source1
                int scroll = dgvServicios.FirstDisplayedScrollingRowIndex;

                dgvServicios.DataSource = source;

                if (scroll != -1)
                {
                    dgvServicios.FirstDisplayedScrollingRowIndex = scroll;
                }
            }
            catch (Win32Exception e)
            {
                e.ToString();
                MessageBox.Show(e.ToString());
            }
        }
コード例 #3
0
ファイル: Servicios.cs プロジェクト: chavy25/Task-Manager
        public void CargarServicios()
        {
            try
            {
                var tablaDatosServ = new DataTable("Ejecutandose");
                source = new BindingSource();

                tablaDatosServ.Columns.Add("Proceso ID");
                tablaDatosServ.Columns.Add("Nombre");
                tablaDatosServ.Columns.Add("Descripcion");
                tablaDatosServ.Columns.Add("Usuario");
                tablaDatosServ.Columns.Add("Estado");


                //int i = 0;  enumeracion de los servicios, pero no es el process id, la enumeracion la puede hacer el gridview

                foreach (var ser in listaServ)
                {
                    serviciosClass = new ServiciosClass();
                    ServiciosClass servicio = obtenerServicio(ser.ServiceName.ToString());

                    serviciosClass.Id              = servicio.Id;
                    serviciosClass.Nombre          = ser.ServiceName.ToString();
                    serviciosClass.Desc            = ser.DisplayName.ToString();
                    serviciosClass.UsuarioServicio = servicio.UsuarioServicio;
                    serviciosClass.Estado          = ser.Status.ToString();

                    if (servicio.Id.Equals("0"))
                    {
                        serviciosClass.Id = string.Empty;
                    }

                    try
                    {
                        tablaDatosServ.Rows.Add(serviciosClass.Id, serviciosClass.Nombre, serviciosClass.Desc, serviciosClass.UsuarioServicio, serviciosClass.Estado);
                    }
                    catch (Exception w32)
                    {
                        MessageBox.Show(w32.Message.ToString(), "Error al Cargar la tabla interna de datos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    //i++;
                }

                try
                {
                    tablaDatosServ.AcceptChanges();
                    source.DataSource = tablaDatosServ;//ejemplo sin utilizar data source2

                    int scroll = dgvServicios.FirstDisplayedScrollingRowIndex;
                    this.dgvServicios.DataSource = source;//ejemplo sin el data source1

                    if (scroll != -1)
                    {
                        dgvServicios.FirstDisplayedScrollingRowIndex = scroll;
                    }
                }
                catch (Exception w32)
                {
                    MessageBox.Show(w32.Message.ToString(), "Error Al Cargar el gridview", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Win32Exception e)
            {
                MessageBox.Show(e.Message.ToString(), "Error Al Cargar Vista", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }