Category Archives: system

Display system metric values with descriptions in C#

The example Get system metrics in C# shows how to get system metrics, but the the metrics’ terse names make the results hard to understand. This example displays descriptions of the metrics in addition to their values. Some of the … Continue reading

Posted in API, system | Tagged , , , , , , , , , , , , , , | Leave a comment

Get system metrics in C#

The GetSystemMetrics API function returns system metrics, values that give dimensions used by the system such as the default size of icons and the thickness of a resizable window’s borders. For example, the highlighted line in the picture on the … Continue reading

Posted in API, system | Tagged , , , , , , , , , , , , | 1 Comment

Get a hard drive serial number in C#

The example Get a disk volume serial number in C# shows how you can find the serial number for a disk volume such as C:\. If you reformat or repartition the drive, however, the volume serial number may change. This … Continue reading

Posted in system | Tagged , , , , , , , , , , , | Leave a comment

Get a disk volume serial number in C#

This example uses the GetVolumeInformation API function so get a disk volume’s serial number. It starts by using the System.Rumtime.InteropServices namespace and by declaring the API function. using System.Runtime.InteropServices; … [DllImport(“kernel32.dll”)] private static extern long GetVolumeInformation( string PathName, StringBuilder VolumeNameBuffer, … Continue reading

Posted in system | Tagged , , , , , , , , , , | 2 Comments

Get the computer’s registered owner and organization in C#

In Windows 98, the system’s registered owner and company name is stored in the following Registry keys: SOFTWARE\Microsoft\Windows\CurrentVersion\RegisteredOwner SOFTWARE\Microsoft\Windows\CurrentVersion\RegisteredOrganization In Windows NT and later, the registered owner and company is stored in the following keys: SOFTWARE\Microsoft\Windows NT\CurrentVersion\RegisteredOwner SOFTWARE\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization This … Continue reading

Posted in registry, system | Tagged , , , , , , , , , | Leave a comment

Get the computer’s operating system in C#

This example uses the following code to display the operating system version when it starts. private void Form1_Load(object sender, EventArgs e) { OperatingSystem os_info = System.Environment.OSVersion; lblOs.Text = os_info.VersionString + “\n\nWindows ” + GetOsName(os_info); } This example simply gets the … Continue reading

Posted in system | Tagged , , , , , , , , , | Leave a comment

Write values in the Registry in C#

The example Read Registry values (to get the desktop icon size) in C# shows how to read values from the Registry. This example shows how to write values into the Registry and uses that ability to refresh the desktop icons … Continue reading

Posted in registry, system | Tagged , , , , , , , , , , | Leave a comment

Read Registry values (to get the desktop icon size) in C#

To make using Registry methods easier, this example defines a RegistryTools class that contains static methods for interacting with the Registry. The following code shows the GetRegistryValue method. // Get a registry value. public static object GetRegistryValue(RegistryKey hive, string subkey_name, … Continue reading

Posted in registry, system | 3 Comments

List USB devices in C#

This program uses WMI (Windows Management Instrumentation) to query for USB devices. To use WMI, add a references to System.Management and add a using System.Management directive. When it starts, this example uses the following code to list USB devices. // … Continue reading

Posted in system | Tagged , , , , , , , | Leave a comment

Activate another running program in C#

This is actually quite simple. First add a reference to the Microsoft.VisualBasic library. Then call Microsoft.VisualBasic.Interaction.AppActivate, passing it the title of the program that you want to activate as in the following code. using Microsoft.VisualBasic; … // Activate the program. … Continue reading

Posted in miscellany, system | Tagged , , , , , , , , , , | Leave a comment