?
Solved

PC's full name

Posted on 2006-06-15
6
Medium Priority
?
791 Views
Last Modified: 2008-02-01
Hi Guys,
               I need to retrieve the PC's full computer name, used to have an API function in VB6, any idea how to get it in C#??

Thanks
Serge
0
Comment
Question by:Autofreak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 6

Assisted Solution

by:neilprice
neilprice earned 200 total points
ID: 16914154
Try this piece of code for an example;

You'll have to set the Properties->Build to allow unsafe code.

using System;
using System.Runtime.InteropServices;

class Class1
{
    [System.Runtime.InteropServices.DllImport("Kernel32")]
    static extern unsafe bool GetComputerName(byte* lpBuffer, long* nSize);

    [STAThread]
    static void Main(string[] args)
    {
        byte[] buffor = new byte[512];
        long size = buffor.Length;
        unsafe
        {
            long* pSize = &size;
            fixed (byte* pBuffor = buffor)
            {
                GetComputerName(pBuffor, pSize);
            }
        }
        System.Text.Encoding textEnc = new System.Text.ASCIIEncoding();
        System.Console.WriteLine("Computer name: {0}", textEnc.GetString(buffor));
        Console.ReadLine();
    }
}

Hope this helps,
Neil
0
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 600 total points
ID: 16914449
Have you tried:

string compName = Environment.MachineName;
0
 
LVL 6

Expert Comment

by:neilprice
ID: 16914984
Haha, that's a lot neater Zephyr :)

Neil
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Expert Comment

by:jvn222
ID: 16917517
FullName

MessageBox.Show(Environment.MachineName + "." Environment.UserDomainName);
0
 
LVL 4

Assisted Solution

by:jvn222
jvn222 earned 200 total points
ID: 16917519
sorry
MessageBox.Show(Environment.MachineName + "." + Environment.UserDomainName);
0
 

Author Comment

by:Autofreak
ID: 16921465
Man, Is C# neat !? Love IT!
Really appreciate your solutions,
Serge
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question