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:
Dim User As String = Windows.Forms.SystemInformation.UserName Dim Domain As String = Windows.Forms.SystemInformation.UserDomainName MessageBox.Show("Good morning " & User & ". You are connected to " _ & Domain)
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).