System Information - C# Programming Exercise

In this exercise, you need to create a program that displays specific system details, including the computer name, domain name, and the username of the currently logged-in user. The program should use the classes provided by C# to retrieve this information from the operating system. You will use classes like Environment and System.Security.Principal.WindowsIdentity to obtain these details, which will help you practice interacting with the operating system and retrieving environment information. This exercise will also help you become familiar with accessing system information in console applications.

 Category

Additional Libraries

 Exercise

System Information

 Objective

Create a program that shows specific system details, including the computer name, domain name, and the username of the user who is currently logged in.

 Write Your C# Exercise

// Import necessary namespaces for working with system information
using System;

class SystemInformation
{
    // Main method where the program execution starts
    static void Main()
    {
        // Display the name of the computer
        Console.WriteLine("Computer Name: " + Environment.MachineName);

        // Display the domain name (or "Workgroup" if not part of a domain)
        Console.WriteLine("Domain Name: " + Environment.UserDomainName);

        // Display the username of the currently logged-in user
        Console.WriteLine("User Name: " + Environment.UserName);
    }
}

 Share this C# exercise

 More C# Programming Exercises of Additional Libraries

Explore our set of C# programming exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of C#. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in C#.

  •  Sitemap creator v2

    In this exercise, you need to create a program that takes three parameters: the name of a text file containing the URLs, the modification date, and the change ...

  •  Surf directory

    In this exercise, you need to create a program that displays the files and folders in the current folder and allows the user to move up and down the list. If the user...

  •  Subdirectories

    In this exercise, you need to create a program that stores the files located in a specific folder and its subfolders. Then, the program should ask the user for a sear...

  •  Date and time

    In this exercise, you need to create a program that displays the current date and time in the following format:"Today is 6 of February of 2015. It´s 03:23:12".

  •  Display directory

    In this exercise, you need to create a program that shows all the files in the current folder. The program should list the files available in the directory where the program...

  •  Display executable files in directory

    In this exercise, you need to create a program that shows the names of all executable files (.com, .exe, .bat, .cmd) in the current folder, excluding the full path. The prog...