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 theclass to determine a number of things about a computer at run time. The following example demonstrates using the SystemInformation class to retrieve the and :
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 () to the spacing of icons in Windows Explorer ( and ).
Some of the more useful members of the SystemInformation class include, , , and .