当执行 Environment.GetEnvironmentVariables() 时,可以得到以下结果(受所安装软件影响,每台电脑都不一样)

Count =
["SystemDrive"]: "C:"
["ProgramFiles(x86)"]: "C:\\Program Files (x86)"
["ProgramW6432"]: "C:\\Program Files"
["PROCESSOR_IDENTIFIER"]: "Intel64 Family 6 Model 60 Stepping 3, GenuineIntel"
["TMP"]: "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp"
["PROCESSOR_ARCHITECTURE"]: "AMD64"
["PATHEXT"]: ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"
["VisualStudioVersion"]: "15.0"
["COMPUTERNAME"]: "C-123"
["PkgDefApplicationConfigFile"]: "C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\VisualStudio\\15.0_b81\\devenv.exe.config"
["SESSIONNAME"]: "Console"
["PROCESSOR_REVISION"]: "3c03"
["TEMP"]: "C:\\Users\\ADMINI~1\\AppData\\Local\\Temp"
["ENABLE_XAML_DIAGNOSTICS_SOURCE_INFO"]: ""
["FPS_BROWSER_USER_PROFILE_STRING"]: "Default"
["LOGONSERVER"]: "\\\\C-123"
["USERNAME"]: "Administrator"
["SystemRoot"]: "C:\\windows"
["VSSKUEDITION"]: "Community"
["USERPROFILE"]: "C:\\Users\\Administrator"
["FPS_BROWSER_APP_PROFILE_STRING"]: "Internet Explorer"
["XAMARIN_ANDROID_REGKEY"]: "SOFTWARE\\Xamarin\\VisualStudio\\15.0_b81\\Android"
["OneDrive"]: "C:\\Users\\Administrator\\OneDrive"
["CommonProgramFiles"]: "C:\\Program Files\\Common Files"
["ProgramData"]: "C:\\ProgramData"
["VSAPPIDDIR"]: "C:\\Program Files\\Microsoft Visual Studio\\2017\\Community\\Common7\\IDE\\"
["HOMEPATH"]: "\\Users\\Administrator"
["MONO_ANDROID_PATH"]: "C:\\Program Files\\Microsoft Visual Studio\\2017\\Community\\MSBuild\\Xamarin\\Android"
["ALLUSERSPROFILE"]: "C:\\ProgramData"
["CommonProgramW6432"]: "C:\\Program Files\\Common Files"
["VisualStudioEdition"]: "Microsoft Visual Studio Community 2017"
["VSLANG"]: ""
["Path"]: "C:\\Program Files\\Java\\jdk1.8.0_181\\bin;C:\\windows\\system32;C:\\windows;C:\\windows\\System32\\Wbem;C:\\windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files (x86)\\Microsoft SQL Server\\100\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\100\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\100\\DTS\\Binn\\;C:\\Program Files (x86)\\Microsoft SQL Server\\100\\Tools\\Binn\\VSShell\\Common7\\IDE\\;C:\\Program Files (x86)\\Microsoft SQL Server\\100\\DTS\\Binn\\;C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\WindowsApps;"
["HOMEDRIVE"]: "C:"
["windir"]: "C:\\windows"
["NUMBER_OF_PROCESSORS"]: ""
["OS"]: "Windows_NT"
["CommonProgramFiles(x86)"]: "C:\\Program Files (x86)\\Common Files"
["ProgramFiles"]: "C:\\Program Files"
["ComSpec"]: "C:\\windows\\system32\\cmd.exe"
["COMPLUS_NoGuiFromShim"]: ""
["JAVA_HOME"]: "C:\\Program Files\\Java\\jdk1.8.0_181"
["PSModulePath"]: "C:\\Program Files\\WindowsPowerShell\\Modules;C:\\windows\\system32\\WindowsPowerShell\\v1.0\\Modules"
["VisualStudioDir"]: "C:\\Users\\Administrator\\Documents\\Visual Studio 2017"
["APPDATA"]: "C:\\Users\\Administrator\\AppData\\Roaming"
["USERDOMAIN"]: "C-123"
["PROCESSOR_LEVEL"]: ""
["LOCALAPPDATA"]: "C:\\Users\\Administrator\\AppData\\Local"
["USERDOMAIN_ROAMINGPROFILE"]: "C-123"
["VSIDE"]: "true"
["PUBLIC"]: "C:\\Users\\Public"
["VSAPPIDNAME"]: "devenv.exe"
["MSBuildLoadMicrosoftTargetsReadOnly"]: "true"

或者这样取值:

Environment.UserDomainName  // 获取与当前用户关联的网络域名。

Environment.ProcessorCount  // 获取当前计算机上的处理器数。

Environment.WorkingSet  //  获取映射到进程上下文的物理内存量。

Environment.Version  //  获取公共语言运行库的版本信息。

Environment.OSVersion  //  获取系统版本号,类似于 Microsoft Windows NT 6.2.9200.0

Environment.GetLogicalDrives()  //  返回当前计算机中的逻辑驱动器名称(数组)。

Environment.GetFolderPath(Environment.SpecialFolder.Desktop)  //  获取桌面路径(逻辑)。

Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)  // 获取桌面路径(物理)。

获取当前操作系统版本:(Win 7、Win 8、Win 10 待完善)

/// <summary>
/// 获取当前运行的操作系统版本。
/// </summary>
/// <returns><see cref="Platform"/> 的值之一,它表示当前运行的操作系统版本。</returns>
private static Platform GetCurrentPlatform()
{
OperatingSystem os = Environment.OSVersion;
Platform pt;
switch(os.Platform)
{
case (PlatformID.Win32Windows): // Win95, Win98 or Me
switch(os.Version.Minor)
{
case (): //
pt = Platform.Windows95;
break;
case (): //
if(os.Version.Revision.ToString() == "2222A")
pt = Platform.Windows982ndEdition;
else
pt = Platform.Windows98;
break;
case (): // winme
pt = Platform.WindowsME;
break;
default: // Unknown
pt = Platform.UnKnown;
break;
}
break;
case (PlatformID.Win32NT): //Win2k or Xp or 2003
switch(os.Version.Major)
{
case ():
pt = Platform.WindowsNT351;
break;
case ():
pt = Platform.WindowsNT40;
break;
case ():
if(os.Version.Minor == )
pt = Platform.Windows2000;
else if(os.Version.Minor == )
pt = Platform.WindowsXP;
else if(os.Version.Minor == )
pt = Platform.Windows2003;
else
pt = Platform.UnKnown;
break;
case ():
pt = Platform.WindowsVista;
break;
default:
pt = Platform.UnKnown;
break;
}
break;
case (PlatformID.WinCE): // WinCE
pt = Platform.WindowsCE;
break;
case (PlatformID.Win32S):
case (PlatformID.Unix):
default:
pt = Platform.UnKnown;
break;
}
return pt;
} /// <summary>
/// 表示操作系统平台。
/// </summary>
private enum Platform : byte
{
/// <summary>
/// Windows 95 操作系统.
/// </summary>
Windows95,
/// <summary>
/// Windows 98 操作系统.
/// </summary>
Windows98,
/// <summary>
/// Windows 98 第二版操作系统.
/// </summary>
Windows982ndEdition,
/// <summary>
/// Windows ME 操作系统.
/// </summary>
WindowsME,
/// <summary>
/// Windows NT 3.51 操作系统.
/// </summary>
WindowsNT351,
/// <summary>
/// Windows NT 4.0 操作系统.
/// </summary>
WindowsNT40,
/// <summary>
/// Windows 2000 操作系统.
/// </summary>
Windows2000,
/// <summary>
/// Windows XP 操作系统.
/// </summary>
WindowsXP,
/// <summary>
/// Windows 2003 操作系统.
/// </summary>
Windows2003,
/// <summary>
/// Windows Vista 操作系统.
/// </summary>
WindowsVista,
/// <summary>
/// Windows CE 操作系统.
/// </summary>
WindowsCE,
/// <summary>
/// 操作系统版本未知。
/// </summary>
UnKnown
}

[转][C#]Environment 类的更多相关文章

  1. Android Environment 类详解

    Android应用开发中,常使用Environment类去获取外部存储目录,在访问外部存储之前一定要先判断外部存储是否已经是可使用(已挂载&可使用)状态, 并且需要在AndroidManife ...

  2. 在外部存储器上写入或读取文件(Environment类、File类的使用)

    1.Environment类 简单介绍:http://www.cnblogs.com/mengdd/p/3742623.html 详细介绍:http://www.2cto.com/kf/201408/ ...

  3. C#核编之System.Environment类

    在前面的例子中用来了Environment.GetCommandLineArgs()这个方法,这个方法就是获取用户的命令行输入,是Environment类的方法之一,该方法的返回值是string[]  ...

  4. Windows系统开发常用类-------------Environment类

    Windows系统开发常用类-------------Environment类:         SystemDirectory//显示系统目录         MachineName//计算机名称 ...

  5. 关于Environment类的使用

    import org.springframework.core.env.Environment; EnvironmentAware 如何引用这个类1.可以通过 @Autowired织入Environm ...

  6. c# 获取系统版本,获取net framework 版本(Environment 类)

    1.获取当前操作系统版本信息 使用Environment.OSVersion 属性 获取包含当前平台标识符和版本号的 OperatingSystem 对象. 命名空间:  System程序集:  ms ...

  7. Environment类,获取程序所在机器信息

    一.属性 CommandLine  获取该进程的命令行.CurrentDirectory 获取或设置当前工作目录的完全限定路径.ExitCode 获取或设置进程的退出代码.HasShutdownSta ...

  8. Environment 类

    提供有关当前环境和平台的信息以及操作它们的方法. 此类不能被继承. using System; using System.Collections; using System.Collections.G ...

  9. C# Environment类_获取程序所在机器信息

    一.属性 CommandLine  获取该进程的命令行.CurrentDirectory 获取或设置当前工作目录的完全限定路径.ExitCode 获取或设置进程的退出代码.HasShutdownSta ...

  10. C# - Environment类,获取桌面的路径

    private void button1_Click(object sender, EventArgs e) { string Path = Environment.GetFolderPath(Env ...

随机推荐

  1. scrapy框架学习之路

    一.基础学习 - scrapy框架 介绍:大而全的爬虫组件. 安装: - Win: 下载:http://www.lfd.uci.edu/~gohlke/pythonlibs/#twisted pip3 ...

  2. 【牛客练习赛22 C】

    https://www.nowcoder.com/acm/contest/132/C 题目大意:在n个区间中取出n个数,相加的和一共会出现多少种结果. 题目分析:对于这种挑选数字相加,由于每一步不同的 ...

  3. Linux 命令的20个实用范例,入门必看!

    Tips: 达内Linux云计算免费课程火热抢报中,点击文末“阅读原文”快速抢! Linux中一个基本命令是ls.没有这个命令,我们会在浏览目录条目时会遇到困难.这个命令必须被每个学习Linux的人知 ...

  4. canvas 使用 isPointInPath() 判断鼠标位置是否在绘制的元素上

    canvas 里绘制的图形不是一个实体 DOM,所以要给每个绘制的图形添加事件操作比给 DOM 添加事件要复杂很多. 所以,我们需要使用一个 canvas 的 isPointInPath(x, y) ...

  5. centos7 添加第三方源

    第三方源下载地址: http://repoforge.org/use/ 选择合适自己包 我选择的是EL7的 wget 下载这个包 接着使用rpm -ivh 包名 确认是否添加成功 ls /etc/yu ...

  6. Cassandra Demo--Python操作cassandra

    ================================================================ 创建keyspace和table CREATE KEYSPACE ex ...

  7. immutable-styles 基本试用

    此文档来自官方文档,从官方demo 学起比较快 安装 官方推荐的是通过webpack 的构建方式,通过babel loader clone 代码 git clone https://github.co ...

  8. java数据类型取值范围

    1个字节:boolean, byte 2个字节:short, char 4个字节:int, float 8个字节:long, double 按照我们初学者的理解1byte=8bit,也就是说1个字节可 ...

  9. es query_string 和 match 的区别

    默认使用 空格拆分成 多个 子项,并且 每个子项 都会去分词 查询.可以通过 default_operator 指定  子项之间的关系.默认是 或 . 然后 每个 子项前面可以使用 -+ 指定必须有 ...

  10. 利用django如何解析用户上传的excel文件

    https://www.jb51.net/article/119452.htm 前言 我们在工作中的时候,会有这种需求:用户上传一个格式固定excel表格到网站上,然后程序负债解析内容并进行处理.我最 ...