Solved

PC's full name

Posted on 2006-06-15
6
790 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 50 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 150 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Expert Comment

by:jvn222
ID: 16917517
FullName

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

Assisted Solution

by:jvn222
jvn222 earned 50 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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