システム情報と Windows フォーム
更新 : 2007 年 11 月
コードにおいて何らかの決定を行うために、アプリケーションが実行されているコンピュータに関する情報を収集することが必要になる場合があります。たとえば、特定のネットワーク ドメインに接続されているときだけ適用できる機能があるとします。この場合は、ドメインを識別し、ドメインが存在しない場合は機能を無効にする方法が必要になります。
Windows フォーム アプリケーションは、SystemInformation クラスを使用して、実行時にコンピュータに関する各種の情報を取得できます。次の例では、SystemInformation クラスを使用して UserName および 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)
SystemInformation クラスのすべてのメンバは、読み取り専用です。ユーザーの設定を変更することはできません。クラスには、コンピュータに接続されているモニタの数を返すもの (MonitorCount) から、Windows エクスプローラのアイコンの間隔を返すもの (IconHorizontalSpacing および IconVerticalSpacing) まで、100 を超えるメンバがあります。
SystemInformation クラスにおける有用なメンバには、ComputerName、DbcsEnabled、PowerStatus、および TerminalServerSession があります。