Connecting Tech Pros Worldwide Forums | Help | Site Map

Get computer name

Gonçalo Boléo
Guest
 
Posts: n/a
#1: Nov 16 '05
How can i get the name of my computer?
Is there any class that gives me access to properties like ComputerName,
Workgroup, Domain?

thnaks,
Gonçalo Boléo



Arne Schittenhelm
Guest
 
Posts: n/a
#2: Nov 16 '05

re: Get computer name


On Sat, 13 Nov 2004 19:59:55 -0000, "Gonçalo Boléo" <goncalo@kaid4.pt>
wrote:
[color=blue]
>How can i get the name of my computer?
>Is there any class that gives me access to properties like ComputerName,
>Workgroup, Domain?
>
>thnaks,
>Gonçalo Boléo
>[/color]

Hello Goncalo,

Try this.

using System.Security.Principal;
WindowsIdentity.GetCurrent().Name.ToString();

This returns a string computer/username.


Thomas P. Skinner [MVP]
Guest
 
Posts: n/a
#3: Nov 16 '05

re: Get computer name


Also check out the System.Windows.Forms.SystemInformation class. It has a
static property that returns the computer name.

Thomas P. Skinner [MVP]

<Arne Schittenhelm> wrote in message
news:l7rcp0dnruj9407ibuhf1fma9mudefha7l@4ax.com...[color=blue]
> On Sat, 13 Nov 2004 19:59:55 -0000, "Gonçalo Boléo" <goncalo@kaid4.pt>
> wrote:
>[color=green]
>>How can i get the name of my computer?
>>Is there any class that gives me access to properties like ComputerName,
>>Workgroup, Domain?
>>
>>thnaks,
>>Gonçalo Boléo
>>[/color]
>
> Hello Goncalo,
>
> Try this.
>
> using System.Security.Principal;
> WindowsIdentity.GetCurrent().Name.ToString();
>
> This returns a string computer/username.
>
>[/color]


Willy Denoyette [MVP]
Guest
 
Posts: n/a
#4: Nov 16 '05

re: Get computer name


Using System.Management and WMI (WinMe, W2K, XP and W2K3).

ManagementObject cs;
using(cs = new ManagementObject ("Win32_ComputerSystem.Name='"+
System.Environment.MachineName + "'"))
{
cs.Get();
if ((bool)cs["partOfDomain"] != null)
{
if ((bool)cs["partOfDomain"] == true)
{
Console.WriteLine("Domain: {0}",cs["domain"]);
}
else
Console.WriteLine("Workgroup: {0}",cs["workgroup"]);
}
else
Console.WriteLine("No domain/Workgrup member");
}

Willy.

"Gonçalo Boléo" <goncalo@kaid4.pt> wrote in message
news:e44JdtbyEHA.3676@TK2MSFTNGP10.phx.gbl...[color=blue]
> How can i get the name of my computer?
> Is there any class that gives me access to properties like ComputerName,
> Workgroup, Domain?
>
> thnaks,
> Gonçalo Boléo
>[/color]


Sharon
Guest
 
Posts: n/a
#5: Nov 16 '05

re: Get computer name


(1) // Gets the string containing the DNS host name of the local computer.
String hostName = Dns.GetHostName();
(2) // Gets the NetBIOS name of this local computer
String hostName = Environment.MachineName;

----
Sharon G.
William Stacey [MVP]
Guest
 
Posts: n/a
#6: Nov 16 '05

re: Get computer name


Environment.MachineName

--
William Stacey, MVP
http://mvp.support.microsoft.com

"Gonçalo Boléo" <goncalo@kaid4.pt> wrote in message
news:e44JdtbyEHA.3676@TK2MSFTNGP10.phx.gbl...[color=blue]
> How can i get the name of my computer?
> Is there any class that gives me access to properties like ComputerName,
> Workgroup, Domain?
>
> thnaks,
> Gonçalo Boléo
>
>[/color]

Closed Thread