Wednesday, July 16, 2014

Create User Account as desired using C sharp - Console Application

To create User Account as desired using C sharp Console Application

Here is a code


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Diagnostics;



namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Do You want to create a user ID in your system?");
            string st = Console.ReadLine();
            if (st == "yes")
            {
                Console.WriteLine("Enter the name of the user to be create:");
                string user = Console.ReadLine();
                Console.WriteLine("Enter the password:");
                string password = Console.ReadLine();
                string userdetails = "@/C" + " " + "net user" + " " + user + " " + password + " " + "/add";
                Process.Start("cmd.exe", userdetails);
                Console.WriteLine("User has been created succesfully");
                Process.Start("cmd.exe", @"/C pause");
            }
            else
                           
               Console.WriteLine("Thank for you not interested in to create user accounts");
                      
           
        }
    }
}

--- If you want to find out whether user account has been created

Press Windows + R
=> cmd
=> net user
Here you will find list of user accounts created

--Happy Coding--

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"