Author Topic: System.Environment Class  (Read 4015 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
System.Environment Class
« on: February 13, 2006, 02:07:14 AM »
For anyone playing around with a Console App
or the System.Environment Class ...
here's a teaser.

Code: [Select]
using System;
using System.Collections.Generic;
using System.Text;

// codehimbelonga kwb : posted@TheSwamp 20060213
// For NET 2.0 Console App

namespace ConsoleApplication20060213A
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.BackgroundColor = ConsoleColor.Blue;
            Console.WindowWidth = 120;
            Console.Clear();

            try {
                DateTime dt = DateTime.Now;
                // http://msdn2.microsoft.com/en-us/library/zdtaw1bw.aspx

                Console.Title = (string.Format(" Console Application Testing : KDUB {0} ",
                                dt.ToString("yyyy, MMM, dd  HH:mm:ss")));

                Console.WriteLine("Current Operating System : {0} ", Environment.OSVersion);
                Console.WriteLine("Current User Name : {0} ", Environment.UserName);
                Console.WriteLine(Environment.NewLine);

                Console.WriteLine("NET Version : {0} ", Environment.Version);

                Console.WriteLine(Environment.NewLine);
                Console.ForegroundColor = ConsoleColor.Black;

                Console.WriteLine("Current Directory : {0} ", Environment.CurrentDirectory);

                Console.WriteLine(Environment.NewLine);
                Console.ForegroundColor = ConsoleColor.White;

                string[] drives = Environment.GetLogicalDrives();
                for (int i = 0; i < drives.Length; i++)
                    Console.WriteLine("Drive {0} : {1} ", i, drives[i]);

                Console.WriteLine(Environment.NewLine);
                Console.ForegroundColor = ConsoleColor.Yellow;

                Console.WriteLine("Personal Folder : {0} ",
                     Environment.GetFolderPath(Environment.SpecialFolder.Personal));

                Console.WriteLine("My Documents Folder : {0} ",
                     Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));

                Console.WriteLine("ProgramFiles Folder : {0} ",
                     Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));

                Console.WriteLine("LocalApplicationData Folder : {0} ",
                     Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));

                Console.WriteLine("Favorites Folder : {0} ",
                     Environment.GetFolderPath(Environment.SpecialFolder.Favorites));

                Console.WriteLine("Internet Cache : {0} ",
                     Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));

                Console.WriteLine(Environment.NewLine);

            } catch (Exception e) { Console.WriteLine(e.ToString()); }
        }
    }
}
« Last Edit: February 13, 2006, 02:21:48 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: System.Environment Class
« Reply #1 on: February 13, 2006, 03:06:04 AM »
... and here's one guaranteed to put bumps on your forehead ..

you'd be looking for MachineName, right , not ComputerName. <which is buried in  System.Windows.Forms.SystemInformation >
.. but the resulting string is the same.
 
Code: [Select]
               Console.WriteLine("Current Computer Name : {0} ",
                    System.Windows.Forms.SystemInformation.ComputerName);

                Console.WriteLine("Current Machine Name : {0} ", Environment.MachineName);
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.