Get environmental!

ddanbe 0 Tallied Votes 710 Views Share

You can get your hands on to usefull information from within your C# program.
Use the static System.Environment class!
Take a look at this snippet, which can be used as is in a Console application.
I have not exhausted all the possibilities, if you want you can look them up in the documentation.

static void ShowEnvironmentInfo()
    {
        // Get the commandline for this process
        //
        Console.WriteLine("Commandline: {0}", Environment.CommandLine);

        // Gets or sets the fully qualified path of the current working directory
        // This is the directory from which this process started.
        //
        Console.WriteLine("Current directory: {0}", Environment.CurrentDirectory);

        // Gets the NetBIOS name of this local machine
        //
        Console.WriteLine("Machine name: {0}", Environment.MachineName);

        // Gets an OperatingSystem object that contains 
        // the current platform identifier and version number.
        //
        Console.WriteLine("OS: {0}", Environment.OSVersion);

        // Gets the network domain name associated with the current user.
        //
        Console.WriteLine("Userdomain name: {0}", Environment.UserDomainName);

        // Print out the drives on this machine,
        //
        foreach (string drive in Environment.GetLogicalDrives())
            Console.WriteLine("Drive: {0}", drive);

        // Gets the number of processors on this machine
        //
        Console.WriteLine("Number of processors: {0}", Environment.ProcessorCount);

        // Gets a Version object that describes the 
        // major, minor, build, and revision numbers of the common language runtime.
        //
        Console.WriteLine(".NET Version: {0}", Environment.Version);

        // Returns a string array containing the command-line arguments for the current process. 
        // Same as string[] args in main 
        //
        Console.WriteLine("Command arguments: {0}", Environment.GetCommandLineArgs());
    }
Usmaan 7 Junior Poster in Training

This is very very very useful! Thank you for putting this up! Really appreciate it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.