Мы поможем в написании ваших работ!



ЗНАЕТЕ ЛИ ВЫ?

Список використаної літератури та онлайн ресурси

Поиск

1. Уотсон К., Нейгел К., Педерсен Я.Х., Рид Дж., Скиннер М. - Visual C#2010 полный курс -2011

2. http://msdn.microsoft.com/ru-ru/library/system.management.managementobjectsearcher.aspx

3. http://www.ua5.org/osnovi/24-zovnshn-pristro-kompjutera.html

4. http://www.ua5.org/osnovi/23-vnutrshn-pristro-kompjutera.html

5. http://www.znannya.org/?view=csharp

 

 

Додаток А

Граф – схема алгоритму утиліти


Лістинг програми

FrmMain.cs

using System;

using System.Collections;

using System.Management;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

 

namespace GetHardwareInfo

{

public partial class frmMain: Form

{

public frmMain()

{

InitializeComponent();

}

 

private void InsertInfo(ref ListView lst)

{

lst.Items.Clear();

 

ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_PnPEntity");

 

try

{

foreach (ManagementObject share in searcher.Get())

{

Device device = new Device();

foreach (PropertyData PC in share.Properties)

{

if(PC.Name == "Name")

{

if (PC.Value!= null && PC.Value.ToString()!= "")

{

device.Name = PC.Value.ToString();

}

else

{

device.Name = "No information";

}

}

 

if (PC.Name == "Description")

{

if (PC.Value!= null && PC.Value.ToString()!= "")

{

device.Description = PC.Value.ToString();

}

else

{

device.Description = "No information";

}

}

 

if (PC.Name == "Manufacturer")

{

if (PC.Value!= null && PC.Value.ToString()!= "")

{

device.Manufacturer = PC.Value.ToString();

}

else

{

device.Manufacturer = "No information";

}

}

 

if (PC.Name == "Service")

{

if (PC.Value!= null && PC.Value.ToString()!= "")

{

device.Service = PC.Value.ToString();

}

else

{

device.Service = "No information";

}

}

 

if (PC.Name == "DeviceID")

{

if (PC.Value!= null && PC.Value.ToString()!= "")

{

device.DeviceId = PC.Value.ToString();

}

else

{

device.DeviceId = "No information";

}

}

 

if (PC.Name == "Status")

{

if (PC.Value!= null && PC.Value.ToString()!= "")

{

device.Status = PC.Value.ToString();

}

else

{

device.Status = "No information";

}

}

}

ListViewItem item = new ListViewItem(new string[] { device.Name, device.Description, device.Manufacturer,

device.Service, device.DeviceId, device.Status});

lst.Items.Add(item);

}

}

catch (Exception exp)

{

MessageBox.Show("can't get data because of the followeing error \n" + exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

}

private void button1_Click(object sender, EventArgs e)

{

InsertInfo(ref lstDisplayHardware);

}

}

public class Device

{

public string Name { get; set; }

public string Description { get; set; }

public string Manufacturer { get; set; }

public string Service { get; set; }

public string DeviceId { get; set; }

public string Status { get; set; }

}

}

 

FrmMainDesiqner.cs

 

namespace GetHardwareInfo

{

partial class frmMain

{

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.IContainer components = null;

/// <summary>

/// Clean up any resources being used.

/// </summary>

/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>

protected override void Dispose(bool disposing)

{

if (disposing && (components!= null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#region Windows Form Designer generated code

 

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmMain));

this.MainTabControl = new System.Windows.Forms.TabControl();

this.tabHardware = new System.Windows.Forms.TabPage();

this.button1 = new System.Windows.Forms.Button();

this.lstDisplayHardware = new System.Windows.Forms.ListView();

this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));

this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));

this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));

this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));

this.columnHeader7 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));

this.columnHeader8 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));

this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));

this.columnHeader6 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));

this.MainTabControl.SuspendLayout();

this.tabHardware.SuspendLayout();

this.SuspendLayout();

//

// MainTabControl

//

this.MainTabControl.Controls.Add(this.tabHardware);

this.MainTabControl.Dock = System.Windows.Forms.DockStyle.Fill;

this.MainTabControl.Location = new System.Drawing.Point(0, 0);

this.MainTabControl.Multiline = true;

this.MainTabControl.Name = "MainTabControl";

this.MainTabControl.SelectedIndex = 0;

this.MainTabControl.Size = new System.Drawing.Size(1129, 479);

this.MainTabControl.TabIndex = 0;

//

// tabHardware

//

this.tabHardware.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));

this.tabHardware.Controls.Add(this.button1);

this.tabHardware.Controls.Add(this.lstDisplayHardware);

this.tabHardware.Location = new System.Drawing.Point(4, 22);

this.tabHardware.Name = "tabHardware";

this.tabHardware.Padding = new System.Windows.Forms.Padding(3);

this.tabHardware.Size = new System.Drawing.Size(1121, 453);

this.tabHardware.TabIndex = 0;

//

// button1

//

this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));

this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;

this.button1.Font = new System.Drawing.Font("Franklin Gothic Heavy", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));

this.button1.ForeColor = System.Drawing.Color.Aqua;

this.button1.Image = ((System.Drawing.Image)(resources.GetObject("button1.Image")));

this.button1.Location = new System.Drawing.Point(2, 0);

this.button1.Name = "button1";

this.button1.Size = new System.Drawing.Size(126, 63);

this.button1.TabIndex = 1;

this.button1.Text = "ВИВЕСТИ ДАНІ";

this.button1.UseVisualStyleBackColor = true;

this.button1.Click += new System.EventHandler(this.button1_Click);

//

// lstDisplayHardware

//

this.lstDisplayHardware.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)

| System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right)));

this.lstDisplayHardware.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));

this.lstDisplayHardware.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {

this.columnHeader1,

this.columnHeader2,

this.columnHeader3,

this.columnHeader4,

this.columnHeader7,

this.columnHeader8});

this.lstDisplayHardware.ForeColor = System.Drawing.Color.Purple;

this.lstDisplayHardware.Location = new System.Drawing.Point(6, 64);

this.lstDisplayHardware.Name = "lstDisplayHardware";

this.lstDisplayHardware.Size = new System.Drawing.Size(1107, 383);

this.lstDisplayHardware.TabIndex = 0;

this.lstDisplayHardware.UseCompatibleStateImageBehavior = false;

this.lstDisplayHardware.View = System.Windows.Forms.View.Details;

//

// columnHeader1

//

this.columnHeader1.Text = "Name";

this.columnHeader1.Width = 250;

//

// columnHeader2

//

this.columnHeader2.Text = "Description";

this.columnHeader2.Width = 250;

//

// columnHeader3

//

this.columnHeader3.Text = "Manufacturer";

this.columnHeader3.Width = 207;

//

// columnHeader4

//

this.columnHeader4.Text = "Service";

this.columnHeader4.Width = 90;

//

// columnHeader7

//

this.columnHeader7.Text = "DeviceId";

this.columnHeader7.Width = 250;

//

// columnHeader8

//

this.columnHeader8.Text = "Status";

this.columnHeader8.Width = 55;

//

// columnHeader5

//

this.columnHeader5.Text = "Name";

this.columnHeader5.Width = 72;

//

// columnHeader6

//

this.columnHeader6.Text = "Value";

this.columnHeader6.Width = 503;

//

// frmMain

//

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

this.ClientSize = new System.Drawing.Size(1129, 479);

this.Controls.Add(this.MainTabControl);

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;

this.Name = "frmMain";

this.Text = "Моніторинг приєднаних пристроїв до комп\'ютера";

this.MainTabControl.ResumeLayout(false);

this.tabHardware.ResumeLayout(false);

this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.TabControl MainTabControl;

private System.Windows.Forms.TabPage tabHardware;

private System.Windows.Forms.ListView lstDisplayHardware;

private System.Windows.Forms.ColumnHeader columnHeader1;

private System.Windows.Forms.ColumnHeader columnHeader2;

private System.Windows.Forms.ColumnHeader columnHeader5;

private System.Windows.Forms.ColumnHeader columnHeader6;

private System.Windows.Forms.ColumnHeader columnHeader3;

private System.Windows.Forms.ColumnHeader columnHeader4;

private System.Windows.Forms.ColumnHeader columnHeader7;

private System.Windows.Forms.ColumnHeader columnHeader8;

private System.Windows.Forms.Button button1;

}

}

Program.cs

using System;

using System.Collections.Generic;

using System.Windows.Forms;

 

namespace GetHardwareInfo

{

static class Program

{

[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new frmMain());

}

}

}

 



Поделиться:


Последнее изменение этой страницы: 2016-07-11; просмотров: 196; Нарушение авторского права страницы; Мы поможем в написании вашей работы!

infopedia.su Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав. Обратная связь - 3.129.253.21 (0.008 с.)