Solved

PC's full name

Posted on 2006-06-15
6
785 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now