Ejemplo n.º 1
0
        /// <summary>
        /// Получает службы через WMI
        /// </summary>
        public void RefreshListService()
        {
            ListViewExistedServices.Items.Clear();

            //Dim search As New ManagementObjectSearcher("SELECT * FROM Win32_Service WHERE PathName like '%ragent.exe%'")
            ManagementObjectSearcher search = new ManagementObjectSearcher("SELECT * FROM Win32_Service WHERE PathName like '%ragent.exe%'");

            int i = 0;

            foreach (ManagementObject info in search.Get())
            {
                /*
                 * Dim Srv = New Service
                 * Srv.Name = info("Name")
                 * Srv.DisplayName = info("DisplayName")
                 * Srv.Description = info("Description")
                 * Srv.PathName = info("PathName")
                 * Srv.User = info("StartName")
                 * Srv.ParsePath()
                 */
                Service1C Srv = new Service1C();
                Srv.Name        = (String)info["Name"];
                Srv.DisplayName = (String)info["DisplayName"];
                Srv.Description = (String)info["Description"];
                Srv.PathName    = (String)info["PathName"];
                Srv.User        = (String)info["StartName"];
                Srv.ParsePath();

                //Dim sc = New System.ServiceProcess.ServiceController(Srv.Name)
                ServiceController sc = new ServiceController(Srv.Name);

                ListViewItem item1 = new ListViewItem(Srv.DisplayName);

                if (sc.Status.ToString() == "Running")
                {
                    item1.SubItems.Add("Работает");
                }
                if (sc.Status.ToString() == "Stopped")
                {
                    item1.SubItems.Add("Остановлена");
                }

                item1.SubItems.Add(Srv.PortMngr.ToString());
                item1.SubItems.Add(Srv.ClusterFiles);
                item1.SubItems.Add(Srv.PathName);

                ListViewExistedServices.Items.Add(item1);


                ArrayOfServices.Add(Srv);

                i++;
            }

            search.Dispose();
            ActivateButton();
        }
Ejemplo n.º 2
0
        private void ListAllServices_DoubleClick(object sender, EventArgs e)
        {
            ListViewItem Item = ListAllServices.SelectedItems[0];

            if (Item.SubItems[0].Text == "AppServer")
            {
                Service1C Serv = new Service1C();
                Serv.ExeFile = Item.SubItems[2].Text;

                ServiceParam ClusterForm = new ServiceParam();
                ClusterForm.ItsAdd = true;
                ClusterForm.Serv   = Serv;
                ClusterForm.ShowDialog();
            }
            Close();
        }