Export (0) Print
Expand All

SystemInformation Class

Provides information about the operating system.

For a list of all members of this type, see SystemInformation Members.

System.Object
   System.Windows.Forms.SystemInformation

[Visual Basic]
Public Class SystemInformation
[C#]
public class SystemInformation
[C++]
public __gc class SystemInformation
[JScript]
public class SystemInformation

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

SystemInformation provides static (Shared in Visual Basic) methods and properties that can be used to get information such as Windows display element sizes, operating system settings, network availability, and the capabilities of hardware installed on the system. This class cannot be instantiated.

Example

[Visual Basic, C#, C++] The following example demonstrates reading system information via the SystemInformation class and adds the information to a ListBox on the form.

[Visual Basic] 
Imports System
Imports System.Drawing
Imports System.Windows.Forms

Public NotInheritable Class Form1
    Inherits System.Windows.Forms.Form

    Friend WithEvents BtnGetScreenInfo As System.Windows.Forms.Button
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox

    <System.STAThread()> _
    Public Shared Sub Main()
        System.Windows.Forms.Application.Run(New Form1())
    End Sub 'Main

    Public Sub New()
        MyBase.New()

        Me.BtnGetScreenInfo = New System.Windows.Forms.Button
        Me.ListBox1 = New System.Windows.Forms.ListBox

        ' Get System Information Button
        Me.BtnGetScreenInfo.Location = New System.Drawing.Point(16, 16)
        Me.BtnGetScreenInfo.Size = New System.Drawing.Size(256, 48)
        Me.BtnGetScreenInfo.TabIndex = 0
        Me.BtnGetScreenInfo.Text = "Get System Information"

        ' System Information ListBox
        Me.ListBox1.Location = New System.Drawing.Point(16, 72)
        Me.ListBox1.Size = New System.Drawing.Size(256, 186)
        Me.ListBox1.TabIndex = 1

        ' Form1
        Me.ClientSize = New System.Drawing.Size(292, 317)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ListBox1, Me.BtnGetScreenInfo})
        Me.Text = "System Information Example"

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGetScreenInfo.Click
        ' Get System Information for the current machine.
        ListBox1.Items.Add("ComputerName : " + SystemInformation.ComputerName)
        ListBox1.Items.Add("Network  : " + SystemInformation.Network.ToString())
        ListBox1.Items.Add("UserDomainName  : " + SystemInformation.UserDomainName)
        ListBox1.Items.Add("UserName   : " + SystemInformation.UserName)
        ListBox1.Items.Add("BootMode : " + SystemInformation.BootMode.ToString())
        ListBox1.Items.Add("MenuFont : " + SystemInformation.MenuFont.ToString())
        ListBox1.Items.Add("MonitorCount : " + SystemInformation.MonitorCount.ToString())
        ListBox1.Items.Add("MonitorsSameDisplayFormat : " + SystemInformation.MonitorsSameDisplayFormat.ToString())
        ListBox1.Items.Add("ArrangeDirection: " + SystemInformation.ArrangeDirection.ToString())
        ListBox1.Items.Add("MousePresent : " + SystemInformation.MousePresent.ToString())
        ListBox1.Items.Add("MouseButtonsSwapped    : " + SystemInformation.MouseButtonsSwapped.ToString())
        ListBox1.Items.Add("UserInteractive    : " + SystemInformation.UserInteractive.ToString())
        ListBox1.Items.Add("VirtualScreen: " + SystemInformation.VirtualScreen.ToString())
    End Sub
End Class

[C#] 
using System;
using System.Drawing;
using System.Windows.Forms;

namespace Screen_Example_cs
{
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.ListBox listBox1;

        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }

        public Form1()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.listBox1 = new System.Windows.Forms.ListBox();

            // Get System Information Button
            this.button1.Location = new System.Drawing.Point(56, 16);
            this.button1.Size = new System.Drawing.Size(168, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "Get System Information";
            this.button1.Click += new System.EventHandler(this.button1_Click);

            // System Information ListBox
            this.listBox1.Location = new System.Drawing.Point(8, 48);
            this.listBox1.Size = new System.Drawing.Size(280, 186);
            this.listBox1.TabIndex = 1;

            // Form1
            this.ClientSize = new System.Drawing.Size(292, 273);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                        this.listBox1, this.button1});
            this.Text = "System Information Example";
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            // Get system information for the current machine.
            listBox1.Items.Add("ComputerName : " + SystemInformation.ComputerName );
            listBox1.Items.Add("Network  : " + SystemInformation.Network  );
            listBox1.Items.Add("UserDomainName  : " + SystemInformation.UserDomainName  );            
            listBox1.Items.Add("UserName   : " + SystemInformation.UserName   );        
            listBox1.Items.Add("BootMode : " + SystemInformation.BootMode );
            listBox1.Items.Add("MenuFont : " + SystemInformation.MenuFont );
            listBox1.Items.Add("MonitorCount : " + SystemInformation.MonitorCount );
            listBox1.Items.Add("MonitorsSameDisplayFormat : " + SystemInformation.MonitorsSameDisplayFormat.ToString() );
            listBox1.Items.Add("ArrangeDirection: " + SystemInformation.ArrangeDirection);
            listBox1.Items.Add("MousePresent : " + SystemInformation.MousePresent );
            listBox1.Items.Add("MouseButtonsSwapped    : " + SystemInformation.MouseButtonsSwapped    );    
            listBox1.Items.Add("UserInteractive    : " + SystemInformation.UserInteractive    );
            listBox1.Items.Add("VirtualScreen: " + SystemInformation.VirtualScreen ); 
        }
    }
}

[C++] 
#using <mscorlib.dll>
#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;

namespace Screen_Example_cs {
public __gc class Form1 : public System::Windows::Forms::Form {
private:
   System::Windows::Forms::Button*  button1;
   System::Windows::Forms::ListBox*  listBox1;
public:
   Form1() {
      this->button1 = new System::Windows::Forms::Button();
      this->listBox1 = new System::Windows::Forms::ListBox();

      // Get System Information Button
      this->button1->Location =  System::Drawing::Point(56, 16);
      this->button1->Size =  System::Drawing::Size(168, 23);
      this->button1->TabIndex = 0;
      this->button1->Text = S"Get System Information";
      this->button1->Click += new System::EventHandler(this, &Form1::button1_Click);

      // System Information ListBox
      this->listBox1->Location =  System::Drawing::Point(8, 48);
      this->listBox1->Size =  System::Drawing::Size(280, 186);
      this->listBox1->TabIndex = 1;

      // Form1
      this->ClientSize =  System::Drawing::Size(292, 273);

      System::Windows::Forms::Control* temp0 [] = {this->listBox1, this->button1};

      this->Controls->AddRange(temp0);
      this->Text = S"System Information Example";
   }
private:
   void button1_Click(Object* /*sender*/, System::EventArgs* /*e*/) {
      // Get system information for the current machine.
      listBox1->Items->Add(String::Format(S"ComputerName : {0}", SystemInformation::ComputerName));
      listBox1->Items->Add(String::Format(S"Network  : {0}", __box(SystemInformation::Network)));
      listBox1->Items->Add(String::Format(S"UserDomainName  : {0}", SystemInformation::UserDomainName));
      listBox1->Items->Add(String::Format(S"UserName   : {0}", SystemInformation::UserName));
      listBox1->Items->Add(String::Format(S"BootMode : {0}", __box(SystemInformation::BootMode)));
      listBox1->Items->Add(String::Format(S"MenuFont : {0}", SystemInformation::MenuFont));
      listBox1->Items->Add(String::Format(S"MonitorCount : {0}", __box(SystemInformation::MonitorCount)));
      listBox1->Items->Add(String::Format(S"MonitorsSameDisplayFormat : {0}", __box(SystemInformation::MonitorsSameDisplayFormat)));
      listBox1->Items->Add(String::Format(S"ArrangeDirection: {0}", __box(SystemInformation::ArrangeDirection)));
      listBox1->Items->Add(String::Format(S"MousePresent : {0}", __box(SystemInformation::MousePresent)));
      listBox1->Items->Add(String::Format(S"MouseButtonsSwapped    : {0}", __box(SystemInformation::MouseButtonsSwapped)));
      listBox1->Items->Add(String::Format(S"UserInteractive    : {0}", __box(SystemInformation::UserInteractive)));
      listBox1->Items->Add(String::Format(S"VirtualScreen: {0}", __box(SystemInformation::VirtualScreen)));
   }
};
}

[STAThread]
int main() {
   Application::Run(new Screen_Example_cs::Form1());
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System.Windows.Forms (in System.Windows.Forms.dll)

See Also

SystemInformation Members | System.Windows.Forms Namespace

Show:
© 2014 Microsoft