SystemInformation.UserName プロパティ
現在のスレッドのユーザー名 (オペレーティング システムに現在ログオンしているユーザーの名前) を取得します。
Public Shared ReadOnly Property UserName As String
[C#]
public static string UserName {get;}
[C++]
public: __property static String* get_UserName();
[JScript]
public static function get UserName() : String;
プロパティ値
オペレーティング システムに現在ログオンしているユーザーの名前。
使用例
[Visual Basic, C#, C++] SystemInformation クラスからシステム情報を読み取り、この情報をフォームの ListBox に追加する方法を次の例に示します。
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
.NET Framework セキュリティ:
- EnvironmentPermission (このプロパティの値を取得するために必要なアクセス許可) PermissionState.Unrestricted (関連する列挙体)
参照
SystemInformation クラス | SystemInformation メンバ | System.Windows.Forms 名前空間