系统信息和 Windows 窗体

更新:2007 年 11 月

有时,为了在编写代码时做出判断,必须收集有关运行应用程序的计算机的信息。例如,您可能有一个仅当连接到特定的网络域时才适用的函数;这种情况下,您需要一种方法来确定该域,或者当该域不存在时禁用该函数。

Windows 窗体应用程序可使用 SystemInformation 类,在运行时确定有关计算机的许多情况。下面的示例演示了如何使用 SystemInformation 类来检索 UserNameUserDomainName

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)

SystemInformation 类的所有成员都是只读的;您无法修改用户的设置。该类有 100 多个成员,用于返回各种信息,从连接到计算机上的监视器的数目 (MonitorCount),到 Windows 资源管理器中图标的间距(IconHorizontalSpacingIconVerticalSpacing)等。

SystemInformation 类的一些更有用的成员包括 ComputerNameDbcsEnabledPowerStatusTerminalServerSession

请参见

概念

Windows 窗体中的电源管理

参考

SystemInformation