This documentation is archived and is not being maintained.

System Information and Windows Forms 

Sometimes it is necessary to gather information about the computer that your application is running on in order to make decisions in your code. For example, you might have a function that is only applicable when connected to a particular network domain; in this case you would need a way to determine the domain and disable the function if the domain is not present.

Windows Forms applications can use the SystemInformation class to determine a number of things about a computer at run time. The following example demonstrates using the SystemInformation class to retrieve the UserName and UserDomainName:

string User = SystemInformation.UserName;
string Domain = SystemInformation.UserDomainName;

MessageBox.Show("Good morning " + User + ". You are connected to " _
+ Domain)

All members of the SystemInformation class are read-only; you cannot modify a user's settings. There are over 100 members of the class, returning information on everything from the number of monitors attached to the computer (MonitorCount) to the spacing of icons in Windows Explorer (IconHorizontalSpacing and IconVerticalSpacing).

Some of the more useful members of the SystemInformation class include ComputerName, DbcsEnabled, PowerStatus, and TerminalServerSession.

See Also