BlackWaspTM

This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

System Information
.NET 1.1+

Get the Registered User and Organisation

When Windows is installed, the user must register a name and, optionally, the name of an organisation. This information is retained by the operating system. When asking for similar details, it is useful to present this information as default values.

System.Management Namespace

The System.Management namespace contains classes that allow you to retrieve information about the system using the Windows Management Instrumentation infrastructure (WMI). This includes a large amount of information about the current system's hardware, processes and operating system, including the names of the registered user and organisation.

The namespace is provided by the System.Management dynamic linked library (DLL). This DLL is not included in Visual Studio projects by default. To access the WMI information, you must add a reference to the DLL to your project. You should also include the following using directive to simplify your code:

using System.Management;

Reading Registration Information

The ManagementClass class can be used to retrieve a WMI class and its associated information. The class to be read is provided to the constructor as a string parameter when generating a new ManagementClass instance. To obtain the registration information, the Win32_OperatingSystem class is needed. To create the appropriate ManagementClass object, add the following code to your project:

ManagementClass mc = new ManagementClass("Win32_OperatingSystem");

Once the ManagementClass object is created, its GetInstances method should be executed to obtain a collection of ManagementObject objects. This collection will contain a single object containing many value, accessible using an indexer. The two string values that we are interested in are named "RegisteredUser" and "Organization".

The following code uses the previously created ManagementClass object to retrieve and output the registered user and organisation:

string registeredUser = null;
string organisation = null;

foreach (ManagementObject mo in mc.GetInstances())
{
    registeredUser = mo["RegisteredUser"].ToString();
    organisation = mo["Organization"].ToString();
}

Console.WriteLine("User:\t{0}", registeredUser);
Console.WriteLine("Org.:\t{0}", organisation);

/* OUTPUT

User:   Richard
Org.:   BlackWasp

*/
15 January 2009