johnc
johnc

Reputation: 40223

Get Computer Name in C# without referencing Microsoft.VisualBasic.dll

Is there any way, other than referencing the Microsoft.VisualBasic.dll (such as as below in .NET 3) to retrieve to Computer Name

new Microsoft.VisualBasic.Devices.ServerComputer().Name

Upvotes: 3

Views: 2162

Answers (2)

JSBձոգչ
JSBձոգչ

Reputation: 41378

You can use System.Windows.Forms.dll and the SystemInformation class. You can also use System.Environment.MachineName or System.Environment.GetEnvironmentVariable("COMPUTERNAME"). And if you're really devoted, you can make a P/Invoke into user32.dll to call the appropriate Win32 API.

Upvotes: 4

Jason Kresowaty
Jason Kresowaty

Reputation: 16500

Use System.Environment.MachineName.

Upvotes: 16

Related Questions