using System; using System.Windows.Forms; class MyDocumentsFolder { public static void Main() { Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.Personal)); foreach (Environment.SpecialFolder s in Enum.GetValues(typeof(Environment.SpecialFolder))) { Console.WriteLine("{0} folder : {1}", s, Environment.GetFolderPath(s)); } } }
Author: coder
Environment.GetFolderPath
using System; using System.Windows.Forms; class MyDocumentsFolder { public static void Main() { Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.Personal)); } }
Environment.CommandLine, Environment.GetCommandLineArgs()
using System; class MainClass { public static void Main(string[] args) { Console.WriteLine(Environment.CommandLine); foreach (string s in Environment.GetCommandLineArgs()) { Console.WriteLine(s); } } }
Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process)
using System; using System.Collections; class MainClass { public static void Main() { IDictionary vars = Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process); foreach (string s in vars.Keys) { if (s.ToUpper().StartsWith("U")) { Console.WriteLine(s + " = " + vars[s]); } } } }
Environment.ExpandEnvironmentVariables
using System; using System.Collections; class MainClass { public static void Main() { Console.WriteLine(Environment.ExpandEnvironmentVariables("The Path on %computername% is %Path%")); } }
Environment.GetEnvironmentVariable
using System; using System.Collections; class MainClass { public static void Main() { Console.WriteLine("Path = " + Environment.GetEnvironmentVariable("Path")); } }
Get Startup path, application name and vendor
using System; using System.Windows.Forms; using Microsoft.Win32; public class MyMessageFilter : IMessageFilter { public bool PreFilterMessage(ref Message m) { // Intercept the left mouse button down message. if (m.Msg == 513) { Console.WriteLine("WM_LBUTTONDOWN is: " + m.Msg); return true; } return false; } } public class mainForm : System.Windows.Forms.Form { private MyMessageFilter msgFliter = new MyMessageFilter(); public mainForm() { GetStats(); Application.ApplicationExit += new EventHandler(Form_OnExit); Application.AddMessageFilter(msgFliter); } [STAThread] static void Main() { Application.Run(new mainForm()); } private void GetStats() { Console.WriteLine(Application.CompanyName+ " Company:"); Console.WriteLine(Application.ProductName+ " App Name:"); Console.WriteLine(Application.StartupPath); } // Event handlers. private void Form_OnExit(object sender, EventArgs evArgs) { Console.WriteLine("Exit", "This app is dead..."); Application.RemoveMessageFilter(msgFliter); } }