Wednesday, July 16, 2014

To find whether system is connected to Domain and find the system name.. !

Hi,

If you would like to find the whether system is connected to work group or domain and find the its name in the C sharp.

Here it is the solution....























(1) Create a Windows forms Application...
(2) Create a button by renaming its text as : GetSystemName
(3) Double click on the button, we will have to code behind to it to execute

Code is as follows:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string domainName = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
            string hostName = Dns.GetHostName();
            string SysName = "";
            if (!hostName.Contains(domainName))
                SysName = hostName + "." + domainName;
             
            else
                SysName = hostName;
            MessageBox.Show("Your System is not connected to Domain!");
            MessageBox.Show("Your Computer Name is "+SysName);

        }

     
    }
}




When you click on the button it will displays as follows,


"Your system is not connected to domain"

and

"Your computer Name is WINSERVER03"




1 comment: