使用Environment 来获取系统的信息

Environment 类可检索信息,如命令行参数、退出代码、环境变量设置、调用堆栈的内容、上次系统引导以来的时间,以及公共语言运行库的版本


    Console.WriteLine("命令行: {0}", Environment.CommandLine);

    String[] arguments = Environment.GetCommandLineArgs();
    Console.WriteLine("命令行参数的字符串数组: {0}", String.Join(", ", arguments));


    Console.WriteLine("当前目录: {0}", Environment.CurrentDirectory);
    Console.WriteLine("机器名: {0}", Environment.MachineName);

    Console.WriteLine("系统换行符: {0}  第1行{0}  第2行{0}  第3行",
                          Environment.NewLine);

    Console.WriteLine("平台标识符和版本号: {0}", Environment.OSVersion.ToString());


    Console.WriteLine("系统目录: {0}", Environment.SystemDirectory);

Console.WriteLine("毫秒数: {0}", Environment.TickCount);
    Console.WriteLine("域: {0}", Environment.UserDomainName);

    Console.WriteLine("交互模式: {0}", Environment.UserInteractive);
    Console.WriteLine("用户名: {0}", Environment.UserName);

    Console.WriteLine("版本: {0}", Environment.Version.ToString());

    Console.WriteLine("临时目录{0}.",
                           Environment.GetEnvironmentVariable("TEMP")); //临时目录

    Console.WriteLine("得到系统环境变量: ");
    IDictionary    environmentVariables = Environment.GetEnvironmentVariables();
    foreach (DictionaryEntry de in environmentVariables)
        {
        Console.WriteLine("  {0} = {1}", de.Key, de.Value);
        }

    Console.WriteLine("系统目录: {0}",
                 Environment.GetFolderPath(Environment.SpecialFolder.System));

    String[] drives = Environment.GetLogicalDrives();
    Console.WriteLine("磁盘: {0}", String.Join(", ", drives));

你可能感兴趣的:(.NET)