Answer the question
In order to leave comments, you need to log in
How to solve the problem with Windows Forms?
Hello, I'm trying to figure out how to create something like a task manager with the ability to view the "stuffing" of a PC.
In general, the so-called "stuffing" is displayed perfectly, but the Listbox does not want to display processes. Tell me what to fix for a newbie please!)
private void button100_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
var processList = Process.GetProcesses();
foreach (var proc in processList)
listBox1.Items.Add(String.Format("{0}.exe", proc.ProcessName));
}
private void button200_Click(object sender, EventArgs e)
{
if (listBox1.SelectedIndex != -1)
{
var taskName = listBox1.Items[listBox1.SelectedIndex].ToString();
taskName = taskName.Substring(0, taskName.Length - 4);
foreach (var procToKill in Process.GetProcessesByName(taskName))
procToKill.Kill();
button100.PerformClick();
}
}
private void listBox1_DoubleClick(object sender, EventArgs e)
{
button200.PerformClick();
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
ManagementObjectSearcher Video1 =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_VideoController");
foreach (ManagementObject vid in Video1.Get())
{
richTextBox1.Clear();
richTextBox1.Text += "-----------------------------------------------------------------------------------------" + "\n";
richTextBox1.Text += " Win32_VideoCard" + "\n";
richTextBox1.Text += "-----------------------------------------------------------------------------------------" + "\n";
richTextBox1.Text +=
" Назва: " + vid.GetPropertyValue("Name") + "\n" +
" Процесор: " + vid.GetPropertyValue("VideoProcessor") + "\n" +
" Відео пам'яті (в Mb): " +Math.Round( System.Convert.ToDouble(vid.GetPropertyValue("AdapterRAM"))/1024/1024)+ "\n" +
" Розширення дисплея: " + vid.GetPropertyValue("VideoModeDescription") + "\n" +
" Обновлення: " + vid.GetPropertyValue("CurrentRefreshRate");
}
}
private void button2_Click(object sender, EventArgs e)
{
ManagementObjectSearcher Processor2 =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Processor");
foreach (ManagementObject proc in Processor2.Get())
{
richTextBox1.Clear();
richTextBox1.Text += "-----------------------------------------------------------------------------------------" + "\n";
richTextBox1.Text += " Win32_Processor" + "\n";
richTextBox1.Text += "-----------------------------------------------------------------------------------------" + "\n";
richTextBox1.Text +=
" Назва: " + proc["Name"] + "\n" +
" Кількість ядер: " + proc["NumberOfCores"] + "\n" +
" Максимальна швидкість (в MHz): " + proc["MaxClockSpeed"] + "\n" +
" Розмір кеша L2 (в Byte): " + proc["L2CacheSize"] + "\n" +
" Id проесора: " + proc["ProcessorId"];
}
}
private void button3_Click(object sender, EventArgs e)
{
ManagementObjectSearcher Memory3 =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_PhysicalMemory");
richTextBox1.Clear();
richTextBox1.Text += "-----------------------------------------------------------------------------------------" + "\n";
richTextBox1.Text += " Win32_Memory" + "\n";
richTextBox1.Text += "-----------------------------------------------------------------------------------------" + "\n";
foreach (ManagementObject mem in Memory3.Get())
{
richTextBox1.Text +=
" Модуль пам'яті (№): " + mem["BankLabel"] + "\n" +
" Потужність (Gb): " + Math.Round(System.Convert.ToDouble(mem["Capacity"]) / 1024 / 1024 / 1024) + "\n" +
" Швидкість (MHz): " + mem["Speed"]+"\n"+
"-------------------------------------------";
richTextBox1.Text += "\n";
}
}
private void button4_Click(object sender, EventArgs e)
{
string hdd1_1 = @"\root\cimv2:Win32_LogicalDisk.DeviceID='C:'";
string hdd1_2 = @"\root\cimv2:Win32_LogicalDisk.DeviceID='D:'";
ManagementObject hdd1 = new ManagementObject(hdd1_1);
ManagementObject hdd2 = new ManagementObject(hdd1_2);
richTextBox1.Clear();
richTextBox1.Text += "-----------------------------------------------------------------------------------------" + "\n";
richTextBox1.Text += " Win32_HDD" + "\n";
richTextBox1.Text += "-----------------------------------------------------------------------------------------" + "\n";
richTextBox1.Text += "\n";
richTextBox1.Text +=
"---HDD Диск (D)---"+"\n"+
" Опис: " + hdd2["Description"] + "\n" +
" Файлова система: " + hdd2["FileSystem"] + "\n" +
" Вільно пам'яті (Gb): " + Math.Round(System.Convert.ToDouble(hdd2["FreeSpace"]) / 1024 / 1024 / 1024) + "\n" +
" Загальний об'єм (Gb): " + Math.Round(System.Convert.ToDouble(hdd2["Size"]) / 1024 / 1024 / 1024);
}
private void button1Os_Click(object sender, EventArgs e)
{
WqlObjectQuery os5 =
new WqlObjectQuery("SELECT * FROM Win32_OperatingSystem");
ManagementObjectSearcher OS =
new ManagementObjectSearcher(os5);
foreach (ManagementObject mo in OS.Get())
{
richTextBox1.Clear();
richTextBox1.Text += "-----------------------------------------------------------------------------------------" + "\n";
richTextBox1.Text += " Win32_OS" + "\n";
richTextBox1.Text += "-----------------------------------------------------------------------------------------" + "\n";
richTextBox1.Text +=
" Назва: " + mo["Caption"] + "\n" +
" Номер збірки: " + mo["BuildNumber"] + "\n"+
" Встановлений пакет оновлення: " + mo["CSDVersion"] + "\n" +
" Ім'я ПК: " + mo["CSName"] + "\n" +
" Дата встановлення ОС: "+
ManagementDateTimeConverter.ToDateTime(mo["InstallDate"].ToString())+"\n"+
" Зареєстрований користувач ОС: " +mo["RegisteredUser"]+"\n"+
" Серійний номер продукту: " +mo["SerialNumber"]+"\n"+
" Фізичний розділ диска з ОС: " +mo["SystemDevice"]+"\n"+
" Системний каталог: " +mo["SystemDirectory"]+"\n"+
" Номер версії ОС: " + mo["Version"]+"\n"+
" Windows каталог: " +mo["WindowsDirectory"];
}
}
private void notifyIcon1_BalloonTipClicked(object sender, EventArgs e)
{
ShowAndRestoreForm();
}
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
ShowAndRestoreForm();
}
private void ShowAndRestoreForm()
{
Show();
WindowState = FormWindowState.Normal;
}
private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
Hide();
}
private void button1_Click_1(object sender, EventArgs e)
{
richTextBox1.Clear();
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_BIOS");
foreach (ManagementObject queryObj in searcher.Get())
{
richTextBox1.Text += "-----------------------------------------------------------------------------------------" + "\n";
richTextBox1.Text += " Win32_BIOS" + "\n";
richTextBox1.Text += "-----------------------------------------------------------------------------------------" + "\n";
if (queryObj["BIOSVersion"] == null)
richTextBox1.Text += " Версія BIOS: " + queryObj["BIOSVersion"]+"\n";
else
{
String[] arrBIOSVersion = (String[])(queryObj["BIOSVersion"]);
foreach (String arrValue in arrBIOSVersion)
{
richTextBox1.Text += " Версія BIOS: " + arrValue + "\n";
}
richTextBox1.Text += " Виробник: " + queryObj["Manufacturer"]+"\n";
richTextBox1.Text += " Серійний номер: " + queryObj["SerialNumber"]+"\n";
} } }
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click_2(object sender, EventArgs e)
{
}
Answer the question
In order to leave comments, you need to log in
using System.Diagnostics;
Process[] processlist = Process.GetProcesses();
foreach(Process theprocess in processlist){
Console.WriteLine(“Process: {0} ID: {1}”, theprocess.ProcessName, theprocess.Id);
}
Maybe you should google it first?
professorweb.ru/my/csharp/assembly/level3/3_2.php
kbyte.ru/ru/Programming/Sources.aspx?id=936&mode=show
www.cyberforum.ru/csharp-net/thread4966.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question