次の方法で共有


システム情報と Windows フォーム

コードにおいて何らかの決定を行うために、アプリケーションが実行されているコンピューターに関する情報を収集することが必要になる場合があります。 たとえば、特定のネットワーク ドメインに接続されているときだけ適用できる機能があるとします。この場合は、ドメインを識別し、ドメインが存在しない場合は機能を無効にする方法が必要になります。

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 クラスにおける有用なメンバーには、ComputerNameDbcsEnabledPowerStatus、および TerminalServerSession があります。

参照

参照

SystemInformation

概念

Windows フォームでの電源管理