BPSoftware.com
Home   Utilities   Purchase   FAQ   Support   Contact        
Shareware Utilities
 APrintDirect
 AIconExtract
 AFile Attribute Manager
Freeware Utilities
 AddrMon
 AFileSync
 ASysIcon
 B&P Table Utilities
 BPACLer
 BPSNMPMon
 BPSNMPUtil
 CharCount
 Delphi® Components
 MacAddr
Miscellaneous
 BPSoftware Blog
 Purchase Shareware
 Support

 Subscribe!

Sunday, February 04, 2007
Those Commercials

As I sit here watching the big game, with the Patriots not in it, I find myself like many others; looking forward to the commercials. The first break just concluded and offered up the first three commercials. The first was a beer commercial (I forget the sponsor) that was a Rock, Paper, Scissors spin off. This was ok, but it did not compare to the Doritos and Blockbuster Video commercials that followed. The Blockbuster commercial with the bunny clicking and dragging the mouse did make me burst out in laughter. There was something sadistically funny about the Doritos commercial that had me laughing quite loudly. Was it the ‘bold’ girl falling on her face or the ‘cheesy’ guy crashing and whacking his 'crunchy' face on the steering wheel? Those will be tough to beat…. I am still undecided on who to cheer for. Being a Patriots fan, I can't say I have a like for either team.

Labels:

posted by Brad Prendergast at 6:44:00 PM (2 comments)
Links to this post
Permalink
System Information and the PerformanceCounter Class

The other day I discussed retrieving system information using the .NET framework. I guess the main focus of that post was to discuss using PInvoke to call unmanaged WIN32 DLL exports, more so than actually retrieving different pieces of system information. The objective of that post was retrieving memory information (I also retrieve disk information in my ‘AboutBox’ discussed in that post). In the 'managed codeworld' there is another way to get different information values. Using the System.Diagnostics.PerformanceCounter Class you can retrieve ‘counter’ information from a local or remote machine. Many of you may be familiar with some of the information accessible through PerformanceCounters if you run the
performance monitor control panel applet.
The information accessible via the System.Diagnostics.PerformanceCounter Class is not limited to just system information. Many services and applications also make ‘counter’ information available for retrieval. Performance Counters are broken out by category (System.Diagnostics.PerformanceCounterCategory). Within each category there many be multiple instances, for example the Logical Disk category will have an instance for each drive, as well as an instance for the _Total of all drives. Each instance will have its own set of counters that can be retrieved. In keeping with the same example, the _Total instance of the Logical Disk category has counters such as ‘% Free Space’, ‘Free Megabytes’ and ‘% Disk Write Time’ to name a few.
Reading counter information is a lot easier than one would expect (the .NET Framework almost made things too easy). I had created a basic-sample PerformanceCounter application that allows for the selection of one of the available (on the local machine) performance counter categories. Once the category is selected, each instance is listed (if there is more than one). Once the counter to be retrieved is selected the value is displayed in a System.Windows.Forms.ListBox (using a System.Timers.Timer for interval). Note: When I use Delphi for development I use the TChart component to display graphs (as I had in BPSNMPMon). If anyone knows of a decent charting control that works with Visual Studio 2005 let me know.


1 System.Diagnostics.PerformanceCounter perfcounter;
2
3 private void cbxPerfCategories_SelectedIndexChanged(object sender, EventArgs e)
4 {
5 cbxInstances.Enabled = true;
6 cbxInstances.Items.Clear();
7 cbxCounters.Items.Clear();
8 lstOutput.Items.Clear();
9 timer1.Enabled = false;
10
11 if (cbxPerfCategories.SelectedIndex != -1)
12 {
13 if (PerformanceCounterCategory.Exists(cbxPerfCategories.Text))
14 {
15 PerformanceCounterCategory perfcategory =
16 new PerformanceCounterCategory(cbxPerfCategories.Text);
17
18 cbxInstances.Items.AddRange(perfcategory.GetInstanceNames());
19 if (cbxInstances.Items.Count == 0)
20 {
21 cbxInstances.Enabled = false;
22 // Get the counters for a category that has only one
23 // instance
24 GetCounters(perfcategory, "",cbxCounters);
25 }

26 }

27 }

28 }

29
30 private void GetCounters(PerformanceCounterCategory perfcategory,
31 string instancename,
32 ComboBox combobox)
33 {
34 System.Diagnostics.PerformanceCounter[] counters;
35 if (instancename.Equals(""))
36 {
37 counters = perfcategory.GetCounters();
38 }

39 else
40 {
41 counters = perfcategory.GetCounters(instancename);
42 }

43 for (int i = 0; i < counters.Length; i++)
44 {
45 combobox.Items.Add(counters[i].CounterName);
46 }

47 }

48
49 private void frmMain_Load(object sender, EventArgs e)
50 {
51 PerformanceCounterCategory[] perfcategories;
52 try
53 {
54 perfcategories = PerformanceCounterCategory.GetCategories();
55 for (int i = 0; i < perfcategories.Length; i++)
56 {
57 cbxPerfCategories.Items.Add(perfcategories[i].CategoryName);
58 }

59 }

60 catch (Exception ex)
61 {
62 MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK,
63 MessageBoxIcon.Error);
64 }

65 }

66
67 private void cbxInstances_SelectedIndexChanged(object sender, EventArgs e)
68 {
69 cbxCounters.Items.Clear();
70 lstOutput.Items.Clear();
71 timer1.Enabled = false;
72
73 if (cbxInstances.SelectedIndex != -1)
74 {
75 if (PerformanceCounterCategory.InstanceExists(cbxInstances.Text, cbxPerfCategories.Text))
76 {
77 PerformanceCounterCategory perfcategory =
78 new PerformanceCounterCategory(cbxPerfCategories.Text);
79 GetCounters(perfcategory, cbxInstances.Text, cbxCounters);
80 }

81 }

82 }

83
84 private void cbxCounters_SelectedIndexChanged(object sender, EventArgs e)
85 {
86 lstOutput.Items.Clear();
87 if (cbxInstances.Text.Equals(""))
88 {
89 perfcounter = new System.Diagnostics.PerformanceCounter(cbxPerfCategories.Text,
90 cbxCounters.Text, true);
91 }

92 else
93 {
94 perfcounter = new System.Diagnostics.PerformanceCounter(cbxPerfCategories.Text,
95 cbxCounters.Text, cbxInstances.Text,true);
96 }

97 timer1.Enabled = true;
98 }

99
100 private void timer1_Tick(object sender, EventArgs e)
101 {
102 float value;
103 value = perfcounter.NextValue();
104 lstOutput.Items.Insert(0,value.ToString("#,##0.00"));
105 }

Labels: , ,

posted by Brad Prendergast at 5:14:00 PM (0 comments)
Links to this post
Permalink
Saturday, February 03, 2007
Cryptography hash and a class - to go

One of the things I appreciate the most in OOP is the concept of classes. I have found that the use of classes allows for code to be easily maintained and reused. I look at classes as neat little packaged objects that can be ‘moved around’ and ‘worked with’ as their own. Another big benefit of classes is the concept of inheritance and polymorphism. In three previous posts (1, 2, 3) I discussed using the System.Security.Cryptography Namespace to calculate the hash values of text (strings) and files. I actually did create a class (that I actively use) from that sample.


1using System;
2using System.Text;
3using System.Security.Cryptography;
4using System.IO;
5
6 public class CryptoHash
7 {
8 /// <summary>
9 /// public enum hashtypes { MD5, SHA1, SHA256, SHA384, SHA512 };
10 /// </summary>

11 public enum hashtypes { MD5, SHA1, SHA256, SHA384, SHA512 };
12
13 Properties
44
45 Constructors
55
56 Methods
199 }

200
201

Labels: , ,

posted by Brad Prendergast at 5:01:00 PM (0 comments)
Links to this post
Permalink
Friday, February 02, 2007
C# LocalAdapterInformation

As I continue to enhance some of my exisiting utilities (and port them to C# ) I found myself working on a utilitiy that determines the Local Network Adapter Information. As I had posted in the past (VB.NET Delphi) here is the C# code for determining the information:
1 public void RetrieveLocalAdapterInformation(TextBox text)
2 {
3 NetworkInterface[] interfaces; // NIC
4 IPInterfaceProperties properties;
5 PhysicalAddress address;
6
7
8 text.Clear();
9
10 try
11 {
12 if (NetworkInterface.GetIsNetworkAvailable())
13 {
14 interfaces = NetworkInterface.GetAllNetworkInterfaces();
15 if (interfaces.GetLength(0) > 0)
16 {
17 foreach (NetworkInterface netInterface in interfaces)
18 {
19 properties = netInterface.GetIPProperties();
20
21 text.AppendText(netInterface.Name + Environment.NewLine);
22 text.AppendText("Id: " + netInterface.Id.ToString() + Environment.NewLine);
23 address = netInterface.GetPhysicalAddress();
24 text.AppendText("MAC Address: " +
25 (address.ToString() == String.Empty ? "None" : address.ToString()) +
26 Environment.NewLine);
27
28 foreach (IPAddressInformation ipinfo in properties.UnicastAddresses)
29 {
30 text.AppendText("IP: " + ipinfo.Address.ToString() +
31 Environment.NewLine);
32 }
33
34 foreach (IPAddress ip in properties.DhcpServerAddresses)
35 {
36 text.AppendText("DHCP Server: " + ip.ToString() +
37 Environment.NewLine);
38 }
39
40 foreach (IPAddress ip in properties.DnsAddresses)
41 {
42 text.AppendText("DNS Server: " + ip.ToString() + Environment.NewLine);
43 }
44
45 text.AppendText("Type: " + netInterface.NetworkInterfaceType.ToString() + Environment.NewLine);
46 text.AppendText("Operational Status: " + netInterface.OperationalStatus.ToString() + Environment.NewLine);
47 text.AppendText("Speed: " + netInterface.Speed.ToString("N") + " bytes" + Environment.NewLine);
48
49 // XP Only
50 System.OperatingSystem osInfo = System.Environment.OSVersion;
51 if ((osInfo.Version.Major == 5) & (osInfo.Version.Minor > 0))
52 {
53 text.AppendText("Receive Only: " +
54 netInterface.IsReceiveOnly.ToString() +
55 Environment.NewLine);
56 text.AppendText("Support Multicast: " +
57 netInterface.SupportsMulticast.ToString() +
58 Environment.NewLine);
59 }
60
61 text.AppendText("Support IPv4: " +
62 netInterface.Supports(NetworkInterfaceComponent.IPv4).ToString() +
63 Environment.NewLine);
64 text.AppendText("Support IPv6: " +
65 netInterface.Supports(NetworkInterfaceComponent.IPv6).ToString() +
66 Environment.NewLine);
67 text.AppendText("DnsSuffix: " +
68 properties.DnsSuffix.ToString() + Environment.NewLine);
69
70 text.AppendText(Environment.NewLine);
71 }
72 }
73 }
74 }
75 catch (Exception e)
76 {
77 MessageBox.Show(e.Message, e.Source, MessageBoxButtons.OK,
78 MessageBoxIcon.Error);
79 }
80 }


As usual a side note: I am always up for trying new things. After reading Steve’s post on a Code Syntax Highlighter; I used that tool for formatting the source code listed above.

Labels: , ,

posted by Brad Prendergast at 8:49:00 AM (0 comments)
Links to this post
Permalink
Recent Posts
 SQL: DBCC CHECKTABLE on multiple tables
 SQL: Index Fragmentation Maintenance
 Off-topic: Uhm, Rickroll?
 SQL: Where are the database files?
 Show Desktop in my QuickLaunch Toolbar?
 Command Line: Visual Source Safe
 SQL: Remove / Delete Orphan Users
 SQL Delete/Drop a User from each Database
 Is there an 'I' in phone?
 SQL Optimization: Am I missing any indexes? - Part...

 Subscribe!


Labels



Archives
 October 2005
 November 2005
 December 2005
 January 2006
 February 2006
 March 2006
 April 2006
 May 2006
 June 2006
 July 2006
 August 2006
 September 2006
 December 2006
 January 2007
 February 2007
 March 2007
 September 2007
 October 2007
 November 2007
 July 2008
 November 2008
Powered by Blogger