Solved

PC's full name

Posted on 2006-06-15
6
786 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

823 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