System and Network Information

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im trying to build an application that will retrieve all system and network information. Im having trouble finding methods, variables, and classes that will help me out. Ive managed to find most of the information but there are still bits and pieces that
I cant find. Below is a list of information I would like information on how to retrieve.


<pre>System:
Operating System Name
OS Directory (Already have the System32 directory)
Total Physical Memory (Not the RAM)
Available Memory
Used Memory

Would also love to get the name of the processor on the computer for example mine is:

Intel(R) Celeron(R) CPU 900 @ 2.20GHz 2.19GHz

Current Network:
Name
SSID
Type
Security Type
Encryption Type
Encryption Key

// For these two Im trying to come up with events that signify when bytes are sent and recieved. Ive already found the variables that tell me the ammount.
Bytes Sent
Bytes Received


Network Interfaces:
Connection-Specific DNS Suffix
IPv4 and IPv6 Connectivity
Media State
DHCP Enabled
SSID
NetBIOS over TCPIP Enabled
IPv4 Address,
Subnet Mask,
WINS Server,
Default Gateway,
DHCP Server,
DNS Server

IPv6 Address (Link Local)
Default Gateway,
DNS Server

Lease Obtained,
Lease Expires[/code]

Here is the source code I have so far so you can see how to help me further in case there are any errors in my code. Im hoping multiple people will help me out with this topic.


<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.ComponentModel;
<span style="color:Blue; using System.Data;
<span style="color:Blue; using System.Drawing;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.Windows.Forms;
<span style="color:Blue; using System.Management;
<span style="color:Blue; using System.Net;
<span style="color:Blue; using System.Net.NetworkInformation;
<span style="color:Blue; using Microsoft.VisualBasic;
<span style="color:Blue; using Microsoft.VisualBasic.Devices;
<span style="color:Blue; using System.Runtime.InteropServices;

<span style="color:Blue; namespace Computer_Information_Panel
{
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class Form1 : Form
{
<span style="color:Blue; public Form1()
{
InitializeComponent();
Runtime.Interval = 1000;
Runtime.Tick += <span style="color:Blue; new EventHandler(UpdateRuntime);
}

<span style="color:Green; // DLL Imports
[DllImportAttribute(<span style="color:#A31515; "user32.dll")]
<span style="color:Blue; public <span style="color:Blue; static <span style="color:Blue; extern <span style="color:Blue; int SendMessage(IntPtr hWnd,
<span style="color:Blue; int Msg, <span style="color:Blue; int wParam, <span style="color:Blue; int lParam);
[DllImportAttribute(<span style="color:#A31515; "user32.dll")]
<span style="color:Blue; public <span style="color:Blue; static <span style="color:Blue; extern <span style="color:Blue; bool ReleaseCapture();

<span style="color:Green; // DLL Hex Address Variables
<span style="color:Blue; public <span style="color:Blue; const <span style="color:Blue; int WM_NCLBUTTONDOWN = 0xA1;
<span style="color:Blue; public <span style="color:Blue; const <span style="color:Blue; int HT_CAPTION = 0x2;

<span style="color:Green; // Network Variables
<span style="color:Blue; private NetworkInterface[] Interfaces = NetworkInterface.GetAllNetworkInterfaces();
<span style="color:Blue; private IPGlobalProperties IPGlobal = IPGlobalProperties.GetIPGlobalProperties();
<span style="color:Blue; private Network MyNetwork = <span style="color:Blue; new Network();

<span style="color:Green; // System Variables
<span style="color:Blue; private OperatingSystem OS = Environment.OSVersion;

<span style="color:Green; // Numeric Values
<span style="color:Blue; private <span style="color:Blue; float InternetSpeed = 0.00f;
<span style="color:Blue; private <span style="color:Blue; long BytesSent = 0;
<span style="color:Blue; private <span style="color:Blue; long BytesReceived = 0;
<span style="color:Blue; private <span style="color:Blue; long Speed;
<span style="color:Blue; private <span style="color:Blue; int Countdown = 10;

<span style="color:Green; // String Values
<span style="color:Blue; private <span style="color:Blue; string OperatingSystem = <span style="color:#A31515; "";
<span style="color:Blue; private <span style="color:Blue; string OperatingSystemVersion = <span style="color:#A31515; "";
<span style="color:Blue; private <span style="color:Blue; string BootMode = <span style="color:#A31515; "";
<span style="color:Blue; private <span style="color:Blue; string ComputerName = <span style="color:#A31515; "";
<span style="color:Blue; private <span style="color:Blue; string UserName = <span style="color:#A31515; "";
<span style="color:Blue; private <span style="color:Blue; string SystemManufactuer = <span style="color:#A31515; "";
<span style="color:Blue; private <span style="color:Blue; string SystemModel = <span style="color:#A31515; "";
<span style="color:Blue; private <span style="color:Blue; string SystemType = <span style="color:#A31515; "";
<span style="color:Blue; private <span style="color:Blue; string OperatingSystemDirectory = <span style="color:#A31515; "";
<span style="color:Blue; private <span style="color:Blue; string SystemDirectory = <span style="color:#A31515; "";
<span style="color:Blue; private <span style="color:Blue; string RAM = <span style="color:#A31515; "";
<span style="color:Blue; private <span style="color:Blue; string TotalMemory = <span style="color:#A31515; "";
<span style="color:Blue; private <span style="color:Blue; string AvailableMemory = <span style="color:#A31515; "";
<span style="color:Blue; private <span style="color:Blue; string UsedMemory = <span style="color:#A31515; "";
<span style="color:Blue; private <span style="color:Blue; string EncryptionKeyShown = <span style="color:#A31515; "Not Available";
<span style="color:Blue; private <span style="color:Blue; string EncryptionKeyHidden = <span style="color:#A31515; "";

<span style="color:Blue; private <span style="color:Blue; void GetBaseSystemInfo()
{
<span style="color:Green; // create management class object
ManagementClass mc = <span style="color:Blue; new ManagementClass(<span style="color:#A31515; "Win32_ComputerSystem");
<span style="color:Green; //collection to store all management objects
ManagementObjectCollection moc = mc.GetInstances();
<span style="color:Blue; if (moc.Count != 0)
{
<span style="color:Blue; foreach (ManagementObject mo <span style="color:Blue; in mc.GetInstances())
{
SystemManufactuer = mo[<span style="color:#A31515; "Manufacturer"].ToString();
SystemModel = mo[<span style="color:#A31515; "Model"].ToString();
SystemType = mo[<span style="color:#A31515; "SystemType"].ToString();
}
}

<span style="color:Blue; double totalCapacity = 0;
ObjectQuery objectQuery = <span style="color:Blue; new ObjectQuery(<span style="color:#A31515; "select * from Win32_PhysicalMemory");
ManagementObjectSearcher searcher = <span style="color:Blue; new ManagementObjectSearcher(objectQuery);
ManagementObjectCollection vals = searcher.Get();

<span style="color:Blue; foreach (ManagementObject val <span style="color:Blue; in vals)
{
totalCapacity += System.Convert.ToDouble(val.GetPropertyValue(<span style="color:#A31515; "Capacity"));
}

RAM = (totalCapacity / 1073741824).ToString() + <span style="color:#A31515; " GB";

SetBaseSystemInfo();
}

<span style="color:Blue; private <span style="color:Blue; void SetBaseSystemInfo()
{
systemManufactuerLabel.Text = <span style="color:#A31515; "System Manufacturer: " + SystemManufactuer;
systemModelLabel.Text = <span style="color:#A31515; "System Model: " + SystemModel;
systemTypeLabel.Text = <span style="color:#A31515; "System Type: " + SystemType;
ramLabel.Text = <span style="color:#A31515; "RAM: " + RAM;
systemTotalMemory.Text = <span style="color:#A31515; "Total Memory: " + TotalMemory;
}

<span style="color:Blue; private <span style="color:Blue; void UpdateNetworkInfo()
{
BytesSent = Interfaces[1].GetIPv4Statistics().UnicastPacketsSent;
BytesReceived = Interfaces[1].GetIPv4Statistics().UnicastPacketsReceived;
Speed = Interfaces[1].Speed / 1000000;
}

<span style="color:Blue; private <span style="color:Blue; void AssignAllNetworkValues()
{
networkSpeed.Text = <span style="color:#A31515; "Speed: " + Speed.ToString() + <span style="color:#A31515; " MB/s";
networkBytesSent.Text = <span style="color:#A31515; "Bytes Sent: " + BytesSent.ToString();
networkBytesReceived.Text = <span style="color:#A31515; "Bytes Received: " + BytesReceived.ToString();
}

<span style="color:Blue; private <span style="color:Blue; void GetNetworkInterfaces(ListBox InterfaceList)
{
<span style="color:Blue; foreach (NetworkInterface Interface <span style="color:Blue; in Interfaces)
InterfaceList.Items.Add(Interface.Name);
}

<span style="color:Blue; private <span style="color:Blue; void Form1_Load(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Green; // Update Copyright Label
toolStripStatusLabel1.Text = <span style="color:#A31515; "Amazing Gaming Inc. " + DateTime.Now.Year.ToString();

<span style="color:Green; // Load Gateway
webBrowser1.Navigate(Interfaces[1].GetIPProperties().GatewayAddresses[0].Address.ToString());

<span style="color:Green; // Network Information
HideEncryptionKey(EncryptionKeyShown);
networkEncryptionKey.Text = <span style="color:#A31515; "Encryption Key: " + EncryptionKeyHidden;
Network.Start();
GetNetworkInterfaces(interfaceList);
UpdateNetworkInfo();
AssignAllNetworkValues();

<span style="color:Green; // System Information
GetBaseSystemInfo();
Runtime.Start();
cpuName.Text = <span style="color:#A31515; "Computer Name: " + SystemInformation.ComputerName;
system32Directory.Text = <span style="color:#A31515; "System 32 Directory: " + Environment.SystemDirectory;
systemOSVersion.Text = <span style="color:#A31515; "OS Version: " + OS.VersionString;
systemBootMode.Text = <span style="color:#A31515; "Boot Mode: " + SystemInformation.BootMode.ToString();
systemUserName.Text = <span style="color:#A31515; "User Name: " + SystemInformation.UserName;
}

<span style="color:Blue; private <span style="color:Blue; void Exit(<span style="color:Blue; object sender, EventArgs e)
{
Application.Exit();
}

<span style="color:Blue; private <span style="color:Blue; void Maximize(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; if (<span style="color:Blue; this.Size != SystemInformation.PrimaryMonitorMaximizedWindowSize)
{
<span style="color:Blue; this.Top = 0;
<span style="color:Blue; this.Left = 0;
<span style="color:Blue; this.Size = SystemInformation.PrimaryMonitorMaximizedWindowSize;
}

<span style="color:Blue; else
{
<span style="color:Blue; this.Top = 200;
<span style="color:Blue; this.Left = 350;
<span style="color:Blue; this.Size = <span style="color:Blue; new Size(646, 417);
}
}

<span style="color:Blue; private <span style="color:Blue; void Minimize(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; this.WindowState = FormWindowState.Minimized;
}

<span style="color:Blue; private <span style="color:Blue; void HighlightExitButton(<span style="color:Blue; object sender, EventArgs e)
{
exitButton.FillColor = Color.Red;
exitButton.FillGradientColor = Color.Maroon;
}

<span style="color:Blue; private <span style="color:Blue; void UnHighlightExitButton(<span style="color:Blue; object sender, EventArgs e)
{
exitButton.FillColor = Color.Maroon;
exitButton.FillGradientColor = Color.Red;
}

<span style="color:Blue; private <span style="color:Blue; void HighlightMaximizeButton(<span style="color:Blue; object sender, EventArgs e)
{
maxButton.FillColor = Color.Lime;
maxButton.FillGradientColor = Color.Green;
}

<span style="color:Blue; private <span style="color:Blue; void UnHighlightMaximizeButton(<span style="color:Blue; object sender, EventArgs e)
{
maxButton.FillColor = Color.Green;
maxButton.FillGradientColor = Color.Lime;
}

<span style="color:Blue; private <span style="color:Blue; void HighlightMinimizeButton(<span style="color:Blue; object sender, EventArgs e)
{
minButton.FillColor = Color.Yellow;
minButton.FillGradientColor = Color.Olive;
}

<span style="color:Blue; private <span style="color:Blue; void UnHighlightMinimizeButton(<span style="color:Blue; object sender, EventArgs e)
{
minButton.FillColor = Color.Olive;
minButton.FillGradientColor = Color.Yellow;
}

<span style="color:Blue; private <span style="color:Blue; void Network_Tick(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; if (Countdown == 0)
{
UpdateNetworkInfo();
AssignAllNetworkValues();
Countdown = 10;
}

<span style="color:Blue; else <span style="color:Blue; if (Countdown == 1)
Countdown--;

<span style="color:Blue; else <span style="color:Blue; if (Countdown == 2)
Countdown--;

<span style="color:Blue; else <span style="color:Blue; if (Countdown == 3)
Countdown--;

<span style="color:Blue; else <span style="color:Blue; if (Countdown == 4)
Countdown--;

<span style="color:Blue; else <span style="color:Blue; if (Countdown == 5)
Countdown--;

<span style="color:Blue; else <span style="color:Blue; if (Countdown == 6)
Countdown--;

<span style="color:Blue; else <span style="color:Blue; if (Countdown == 7)
Countdown--;

<span style="color:Blue; else <span style="color:Blue; if (Countdown == 8)
Countdown--;

<span style="color:Blue; else <span style="color:Blue; if (Countdown == 9)
Countdown--;

<span style="color:Blue; else <span style="color:Blue; if (Countdown == 10)
Countdown--;

networkCountdown.Text = <span style="color:#A31515; "Next Update In: " + Countdown.ToString() + <span style="color:#A31515; "s";
}

<span style="color:Blue; private <span style="color:Blue; void HighlightGrip(<span style="color:Blue; object sender, MouseEventArgs e)
{
Grip.FillColor = Color.LightSkyBlue;
Grip.FillGradientColor = Color.Navy;

<span style="color:Blue; if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}

<span style="color:Blue; private <span style="color:Blue; void UnHighlightGrip(<span style="color:Blue; object sender, MouseEventArgs e)
{
Grip.FillColor = Color.Navy;
Grip.FillGradientColor = Color.LightSkyBlue;
}

<span style="color:Blue; private <span style="color:Blue; void aboutToolStripMenuItem_Click(<span style="color:Blue; object sender, EventArgs e)
{
About x = <span style="color:Blue; new About();
x.Show();
}

<span style="color:Blue; private <span style="color:Blue; void HideEncryptionKey(<span style="color:Blue; string EncryptionKey)
{
EncryptionKeyHidden = <span style="color:#A31515; "";

<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < EncryptionKey.Length; i++)
EncryptionKeyHidden += <span style="color:#A31515; "* ";
}

<span style="color:Blue; private <span style="color:Blue; void checkBox1_CheckedChanged(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; if (networkHideShowEncryption.Checked)
networkEncryptionKey.Text = <span style="color:#A31515; "Encryption Key: " + EncryptionKeyHidden;

<span style="color:Blue; else
networkEncryptionKey.Text = <span style="color:#A31515; "Encryption Key: " + EncryptionKeyShown;
}

<span style="color:Blue; private <span style="color:Blue; void ViewInterfaceInformation(<span style="color:Blue; object sender, EventArgs e)
{
interfacePhysical.Text = <span style="color:#A31515; "Physical Address: " + Interfaces[interfaceList.SelectedIndex].GetPhysicalAddress().ToString();
}

<span style="color:Blue; private <span style="color:Blue; void CopySystemInfo(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; string SystemInfo = <span style="color:#A31515; "";

SystemInfo += cpuName.Text + Environment.NewLine;
SystemInfo += systemOS.Text + Environment.NewLine;
SystemInfo += systemOSVersion.Text + Environment.NewLine;
SystemInfo += systemManufactuerLabel.Text + Environment.NewLine;
SystemInfo += systemModelLabel.Text + Environment.NewLine;
SystemInfo += systemOSDirectory.Text + Environment.NewLine;
SystemInfo += system32Directory.Text + Environment.NewLine;
SystemInfo += systemBootMode.Text + Environment.NewLine;
SystemInfo += systemTotalMemory.Text + Environment.NewLine;
SystemInfo += systemAvailableMemory.Text + Environment.NewLine;
SystemInfo += systemUsedMemory.Text + Environment.NewLine;
SystemInfo += systemRuntimeLabel.Text;

Clipboard.SetText(SystemInfo);
}

<span style="color:Blue; private <span style="color:Blue; void CopyNetworkInfo(<span style="color:Blue; object sender, EventArgs e)
{

}

<span style="color:Blue; private <span style="color:Blue; void CopyInterfaceInfo(<span style="color:Blue; object sender, EventArgs e)
{

}

<span style="color:Blue; private <span style="color:Blue; void CopyAllInfo(<span style="color:Blue; object sender, EventArgs e)
{

}

<span style="color:Blue; private <span style="color:Blue; void UpdateRuntime(<span style="color:Blue; object sender, EventArgs e)
{
systemRuntimeLabel.Text = <span style="color:#A31515; "System Runtime: " + (Environment.TickCount / 1000).ToString() + <span style="color:#A31515; "s";
}
}
}
[/code]

Thanks,
Jamie

View the full article
 
Back
Top