Beispiel #1
0
        private void genButton_Click(object sender, EventArgs e)
        {
            is_localhost = is_local.Checked;
            if (l_events.SelectedIndex == -1)
            {
                MessageBox.Show("Не выбран тип данных", "Ошибка");
                return;
            }


            if (!is_localhost)
            {
                if (user == null)
                {
                    MessageBox.Show("Необходимо ввести учетные данные пользователя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (clients == null)
                {
                    MessageBox.Show("Не выбран ни один клиент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                Handler.setUser(user, password, impLevel, authLevel);
            }
            else
            {
                clients = new List <string>()
                {
                    "localhost"
                };
            }

            Output.Text = "";
            string result = null;

            foreach (string serverName in clients)
            {
                switch (l_events.SelectedIndex)
                {
                case 0:    //files
                    if (Path.Text == "")
                    {
                        MessageBox.Show("Введите путь", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    if (!Regex.IsMatch(Path.Text, rgx))
                    {
                        MessageBox.Show("Неправильно введен путь\nПример: C:\\Users\\admin", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    char   drive = Path.Text[0];
                    string path  = Path.Text.Substring(2);
                    if (path == "\\")
                    {
                        path += '.';
                    }
                    string       extension = Extension.Text.Replace(".", "");
                    WMI_FileInfo fi        = new WMI_FileInfo(extension, drive, path);
                    result = Handler.collect(fi, serverName);
                    break;

                case 1:    //processes
                    result = Handler.collect(new WMI_Process(), serverName);
                    break;

                case 2:    //services
                    result = Handler.collect(new WMI_Services(serviceType.SelectedIndex), serverName);
                    break;

                case 3:    //network
                    result = Handler.collect(new WMI_NetworkInfo(), serverName);
                    break;

                case 4:    //devices
                    result = Handler.collect(new WMI_Device(), serverName);
                    break;

                case 5:    //logons
                    if ((int)range.Value <= 0)
                    {
                        MessageBox.Show("Введите корректный диапазон времени", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    result = Handler.collect(new WMI_LogonInfo((int)range.Value), serverName);
                    break;

                case 6:    //drives
                    result = Handler.collect(new WMI_DriveInfo(), serverName);
                    break;
                }
                TreeNode[] node = treeView1.Nodes.Find(serverName, false);
                MessageBox.Show(node.ToString());
                Output.Text = "\r\n=====================================";
                if (result != null)
                {
                    Output.Text = result + Output.Text + "\r\nЗапрос успешно завершен\r\n";
                }
                else
                {
                    Output.Text += "\r\nЗапрос не выдал результатов\r\n";
                    continue;
                }
            }
        }
Beispiel #2
0
        private void get_info()
        {
            tabControl1.SelectedIndex = 0;
            if (!check())
            {
                return;
            }
            string[] tts = new string[targets.CheckedItems.Count];
            for (int i = 0; i < targets.CheckedItems.Count; i++)
            {
                tts[i] = targets.CheckedItems[i].ToString();
            }
            WMI_class result_info = null;

            switch (info_type)
            {
            case 0:
                result_info = new WMI_FileInfo(ext, drive, path);
                break;

            case 1:
                result_info = new WMI_Process();
                break;

            case 2:
                result_info = new WMI_Services(service_type);
                break;

            case 3:
                result_info = new WMI_LogonInfo(time_range);
                break;

            case 4:
                result_info = new WMI_NetworkInfo();
                break;

            case 5:
                result_info = new WMI_Device();
                break;

            case 6:
                result_info = new WMI_DriveInfo();
                break;

            case 7:
                result_info = new WMI_Startup();
                break;

            case 8:
                result_info = new WMI_Apps();
                break;
            }
            output.Nodes.Clear();
            TreeNode result;

            for (int i = 0; i < tts.Length; i++)
            {
                TreeNode node = new TreeNode(tts[i]);
                Handler.setUser(login, password, impLevel, authLevel);
                result = Handler.collect(result_info, tts[i]);
                if (result == null)
                {
                    node.Nodes.Add("Ошибка");
                }
                else
                {
                    foreach (TreeNode n in result.Nodes)
                    {
                        switch (info_type)
                        {
                        case 0:
                            n.ContextMenuStrip = file_context;
                            break;

                        case 1:
                            n.ContextMenuStrip = process_context;
                            break;
                        }
                    }
                    node.Nodes.Add(result);
                }
                node.ContextMenuStrip = target_settings;
                output.Nodes.Add(node);
            }
        }