C Shap Samples
C Shap Samples
Program Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class IO_Manager : Form
{
string Foldername = @"F:\Csharp";
string winDir = System.Environment.GetEnvironmentVariable("windir");
public IO_Manager()
{
InitializeComponent();
}
private void addListItem(string value)
{
this.listBox1.Items.Add(value);
}
}
else
{
MessageBox.Show("Directory already exists");
}
not
Program Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Win32;
using System.IO;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Management;
using System.Security;
using System.IO.Ports;
namespace WindowsFormsApplication1
{
public partial class devices : Form
{
public devices()
{
InitializeComponent();
}
RegistryKey Regkey, RegKey2;
Int32 rValue, rsvalue, Gvalue, tvalue;
string Regpath = "System\\CurrentControlSet\\Services\\USBSTOR";
string ReadAndWriteRegPath2 = "System\\CurrentControlSet\\Control";
string ReadAndWriteRegPath = "System\\CurrentControlSet\\Control\\
StorageDevicePolicies";
}
}
3.Power options—The program restarts, shutdowns, sign user out of the computer and puts it
to sleep mode.
Program code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class power : Form
{
[DllImport("user32")]
public static extern void LockWorkStation();
public power()
{
InitializeComponent();
}
[DllImport("user32")]
public static extern bool ExitWindowsEx(GraphicsUnit uFlags, uint DwReason);
{//shurts computer
Process.Start("shutdown.exe", "-s -t 00");
}
}
}
}
2.Process Management
It is another mdiparent form menu item which has the processes that is it can start apps such
as word excel notepad and others. At the same time the started apps can be killed, I
implemented using the combo box whereby we select the program you want to kill.
Program code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsFormsApplication1
{
public partial class Processmgn : Form
{
public Processmgn()
{
InitializeComponent();
}
Program code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Management;
using System.Diagnostics;
using System.Dynamic;
namespace WindowsFormsApplication1
{
public partial class frmprocesses : Form
return response;
}
public string BytesToReadableValue(long number)
{
List<string> suffixes = new List<string> { " B", " KB", " MB", " GB", " TB", "
PB" };
if (temp == 0)
{
return (number / (int)Math.Pow(1024, i)) + suffixes[i];
}
}
return number.ToString();
}
public frmprocesses()
{
InitializeComponent();
}
//
// As not every process has an icon then, prevent the app from crash
try
{
Imagelist.Images.Add(
// Add an unique Key as identifier for the icon (same as the ID of
the process)
process.Id.ToString(),
// Add Icon to the List
Icon.ExtractAssociatedIcon(process.MainModule.FileName).ToBitmap()
);
}
catch { }
// Create a new Item to add into the list view that expects the row of
information as first argument
ListViewItem item = new ListViewItem(row)
{
// Set the ImageIndex of the item as the same defined in the previous
try-catch
ImageIndex = Imagelist.Images.IndexOfKey(process.Id.ToString())
};
}
}
3.Memory Management
It is menu item number three in the mdi parent form. In this the program lists all the disk
partitions, the space used and space available for each partition.
Program code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Memory : Form
{
public Memory()
{
InitializeComponent();
getdrive();
}
private void getdrive()
{
{ }
}
private void bunifuFlatButton1_Click(object sender, EventArgs e)
{
MessageBox.Show(" COMPUTER HARDWARE INFORMATION");
int NoOfDisk = 0;
foreach (DriveInfo drinfo in DriveInfo.GetDrives())
{
MessageBox.Show("DriveName" + drinfo.Name + "\n"
+ "DriveLabel :" + drinfo.VolumeLabel + "\n"
+ "Total Space:" + drinfo.TotalSize / 1073741824 + " GB\n"
+ "Total Free Space:" + drinfo.TotalFreeSpace / 1073741824 + " GB\n"
+ "DriveType :" + drinfo.DriveType
);
}
MessageBox.Show("Total Disk:" + (NoOfDisk - 1).ToString());
}
}
}
}
4.Communication Management
In communication management I implemented sockets, signals, Rpc and Serial
communication. Serial communication enables communication between ports (COM3,
COM4, COM5). Rpc implements remote communication where commands are typed in the
command prompt. Signals implement the use of timers for an event to occur.
Serial Communication
Program Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace WindowsFormsApplication1
{
public partial class communication : Form
{
public communication()
{
InitializeComponent();
}
try
{
if (serialPort1.IsOpen)
{
serialPort1.WriteLine(textBox1.Text+Environment.NewLine);
textBox1.Clear();
}
}
catch (Exception ex)
{
serialPort1.Open();
}
catch (Exception ex)
{
RPC
Program code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Rpc : Form
{
public Rpc()
{
InitializeComponent();
}
}
}
}
}
Signal
Program Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
pictureBox1.Visible = true;
pictureBox2.Visible = false;
pictureBox3.Visible = false;
}
}
}
}
Socket
Program Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
namespace monday
{
public partial class socket : Form
{
Socket sck;
EndPoint epLocal, epRemote;
byte[] buffer;
public socket()
{
InitializeComponent();
}
}
private string GetLocalIP()
{
IPHostEntry host;
host= Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList) {
if (ip.AddressFamily == AddressFamily.InterNetwork)
return ip.ToString();
}
return "10.10.152.212";
}
listmesage.Items.Add("receaver:" + ReceavedMessage);
buffer = new byte[1500];
sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref
epRemote, new AsyncCallback(MessageCallBack), buffer);
}
catch (Exception ex) { MessageBox.Show(ex.ToString()); }
}
}
}
5.Information Management
This gives the device name and the user logged in. It Displays the Pc Ip address.
Program Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
namespace WindowsFormsApplication1
{
public partial class frminformation : Form
{
public frminformation()
{
InitializeComponent();
}