代码:
Environment.MachineName
结果示例:
"BOBOPO.COM"
代码:
Environment.UserName
结果示例:
"Bobopo"
代码:
Environment.ProcessorCount
结果示例:
1
代码:
Environment.OSVersion.VersionString
结果示例:
"Microsoft Windows NT 5.1.2600 Service Pack 2"
代码:
Environment.OSVersion.Version.ToString
结果示例:
"5.1.2600.131072"
代码:
Environment.OSVersion.ServicePack
结果示例:
"Service Pack 2"
代码:
Environment.Version.ToString
结果示例:
"2.0.50727.1433"
代码:
Directory.GetParent(Environment.SystemDirectory).FullName
结果示例:
"C:\WINDOWS"
代码:
Environment.SystemDirectory
结果示例:
"C:\WINDOWS\system32"
代码:
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
结果示例:
"C:\Program Files"
代码:
Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles)
结果示例:
"C:\Program Files\Common Files"
代码:
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
结果示例:
"C:\Documents and Settings\All Users\Application Data"
代码:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
结果示例:
"C:\Documents and Settings\Bobopo\Application Data"
代码:
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
结果示例:
"C:\Documents and Settings\Bobopo\Desktop"
代码:
Environment.GetFolderPath(Environment.SpecialFolder.Cookies)
结果示例:
"C:\Documents and Settings\Bobopo\Cookies"
代码:
Environment.GetFolderPath(Environment.SpecialFolder.Favorites)
结果示例:
"C:\Documents and Settings\Bobopo\Favorites"
代码:
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
结果示例:
"C:\Documents and Settings\Bobopo\My Documents"
代码:
Environment.GetFolderPath(Environment.SpecialFolder.StartMenu)
结果示例:
"C:\Documents and Settings\Bobopo\Start Menu"
代码:
Environment.GetFolderPath(Environment.SpecialFolder.Recent)
结果示例:
"C:\Documents and Settings\Bobopo\Recent"
代码:
Environment.GetFolderPath(Environment.SpecialFolder.Templates)
结果示例:
"C:\Documents and Settings\Bobopo\Templates"
代码:
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
结果示例:
"C:\Documents and Settings\Bobopo\Local Settings\Application Data"
代码:
Environment.GetFolderPath(Environment.SpecialFolder.History)
结果示例:
"C:\Documents and Settings\Bobopo\Local Settings\History"
似乎.Net中并没有一种直接的方法获得操作系统的名称,至少我没有找到。不过可以通过Environment.OSVersion中的内部版本号来推断出操作系统的名称。
与操作系统名称相关的Environment.OSVersion属性如下:
具体的推断关系如下表所示:
操作系统名称 | Platform | Version.Major | Version.Minor |
---|---|---|---|
Windows 3.1 | 0 | ? | ? |
Windows 95 | 1 | 4 | 0 |
Windows 98 | 1 | 4 | 10 |
Windows Me | 1 | 4 | 90 |
Windows NT 3.51 | 2 | 3 | 51 |
Windows NT 4.0 | 2 | 4 | 0 |
Windows 2000 | 2 | 5 | 0 |
Windows XP | 2 | 5 | 1 |
Windows 2003 | 2 | 5 | 2 |
Windows Vista | 2 | 6 | 0 |
需要指出的是,目前尚未发布的Windows 2008和Windows Vista具有相同的特征,所以用这种方法无法区分这两个版本。
可以用下面的函数来计算出操作系统的名称。
Public Shared Function GetOSVersionText() As String
Dim v As Version = Environment.OSVersion.Version
Select Case Environment.OSVersion.Platform
Case PlatformID.Win32S : Return "3.1"
Case PlatformID.Win32Windows
Select Case v.Minor
Case 0 : Return "95"
Case 10 : Return "98"
Case 90 : Return "Me"
End Select
Case PlatformID.Win32NT
Select Case v.Major
Case 3 : Return "NT 3.51"
Case 4 : Return "NT 4.0"
Case 5
Select Case v.Minor
Case 0 : Return "2000"
Case 1 : Return "XP"
Case 2 : Return "2003"
End Select
Case 6 : Return "Vista"
End Select
Case PlatformID.WinCE
Return "CE " & v.Major.ToString & "." & v.Minor.ToString
End Select
Return "Unknown"
End Function
代码:
"Microsoft Windows " & GetOSVersionText()
结果示例:
"Microsoft Windows XP"
代码:
"Microsoft Windows " & GetOSVersionText() & " " & Environment.OSVersion.ServicePack
结果示例:
"Microsoft Windows XP Service Pack 2"
文章评论(0条评论)
登录后参与讨论