对不起,有的手误,现在更正:Option ExplicitPrivate Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
End Type
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Const VER_PLATFORM_WIN32s = 0
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Const SM_CLEANBOOT = 67
Private Const SM_DEBUG = 22
Private Const SM_SLOWMACHINE = 73Private m_udtVersionInfo As OSVERSIONINFO
Private m_lngRet As LongPublic Enum enumSystemStatus
ssNormal = 0 '"正常模式"
ssSafeMode = 1 '"安全模式"
ssSafeModeWithNetwork = 2 '"带网络支持的安全模式"
ssDebug = 3 '"Windows 排错模式"
ssSlowMachine = 4 '"这台机器太慢以致不能流畅的运行Windows"
End EnumPublic Enum enumSystemPlatform
spWindows = 1
spWinNT = 2
End EnumPrivate Sub InitializeSystemInfo()
m_udtVersionInfo.dwOSVersionInfoSize = 148
m_lngRet = GetVersionEx(m_udtVersionInfo)
End Sub
Public Function GetSystemPlatform() As enumSystemPlatform
Select Case m_udtVersionInfo.dwPlatformId
Case VER_PLATFORM_WIN32_WINDOWS
GetSystemPlatform = spWindows
Case VER_PLATFORM_WIN32_NT
GetSystemPlatform = spWinNT
Case Else
GetSystemPlatform = spWindows
End Select
End Function
Public Function GetSystemStatus() As enumSystemStatus If GetSystemMetrics(SM_CLEANBOOT) = 0 Then
GetSystemStatus = ssNormal '"正常模式"
ElseIf GetSystemMetrics(SM_CLEANBOOT) = 1 Then
GetSystemStatus = ssSafeMode '= "安全模式"
ElseIf GetSystemMetrics(SM_CLEANBOOT) = 2 Then
GetSystemStatus = ssSafeModeWithNetwork '"带网络支持的安全模式"
ElseIf GetSystemMetrics(SM_DEBUG) Then
GetSystemStatus = ssDebug '"Windows 排错模式"
ElseIf GetSystemMetrics(SM_SLOWMACHINE) Then
GetSystemStatus = ssSlowMachine '"这台机器太慢以致不能流畅的运行Windows"
End IfEnd Function
Public Function GetSystemMajorVersion() As String
GetSystemMajorVersion = m_udtVersionInfo.dwMajorVersion '& "." & m_udtVersionInfo.dwMinorVersion & " Build " & (m_udtVersionInfo.dwBuildNumber And &HFFFF&)End Function
Public Function GetSystemMinorVersion() As String
GetSystemMinorVersion = m_udtVersionInfo.dwMinorVersion & " Build " & (m_udtVersionInfo.dwBuildNumber And &HFFFF&)End Function
Public Function GetSystemBuildVersion() As Long
GetSystemBuildVersion = (m_udtVersionInfo.dwBuildNumber And &HFFFF&)End Function
Private Sub Class_Initialize()
InitializeSystemInfo
End Sub
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
End Type
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Const VER_PLATFORM_WIN32s = 0
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Const SM_CLEANBOOT = 67
Private Const SM_DEBUG = 22
Private Const SM_SLOWMACHINE = 73Private m_udtVersionInfo As OSVERSIONINFO
Private m_lngRet As LongPublic Enum enumSystemStatus
ssNormal = 0 '"正常模式"
ssSafeMode = 1 '"安全模式"
ssSafeModeWithNetwork = 2 '"带网络支持的安全模式"
ssDebug = 3 '"Windows 排错模式"
ssSlowMachine = 4 '"这台机器太慢以致不能流畅的运行Windows"
End EnumPublic Enum enumSystemPlatform
spWindows = 1
spWinNT = 2
End EnumPrivate Sub InitializeSystemInfo()
m_udtVersionInfo.dwOSVersionInfoSize = 148
m_lngRet = GetVersionEx(m_udtVersionInfo)
End Sub
Public Function GetSystemPlatform() As enumSystemPlatform
Select Case m_udtVersionInfo.dwPlatformId
Case VER_PLATFORM_WIN32_WINDOWS
GetSystemPlatform = spWindows
Case VER_PLATFORM_WIN32_NT
GetSystemPlatform = spWinNT
Case Else
GetSystemPlatform = spWindows
End Select
End Function
Public Function GetSystemStatus() As enumSystemStatus If GetSystemMetrics(SM_CLEANBOOT) = 0 Then
GetSystemStatus = ssNormal '"正常模式"
ElseIf GetSystemMetrics(SM_CLEANBOOT) = 1 Then
GetSystemStatus = ssSafeMode '= "安全模式"
ElseIf GetSystemMetrics(SM_CLEANBOOT) = 2 Then
GetSystemStatus = ssSafeModeWithNetwork '"带网络支持的安全模式"
ElseIf GetSystemMetrics(SM_DEBUG) Then
GetSystemStatus = ssDebug '"Windows 排错模式"
ElseIf GetSystemMetrics(SM_SLOWMACHINE) Then
GetSystemStatus = ssSlowMachine '"这台机器太慢以致不能流畅的运行Windows"
End IfEnd Function
Public Function GetSystemMajorVersion() As String
GetSystemMajorVersion = m_udtVersionInfo.dwMajorVersion '& "." & m_udtVersionInfo.dwMinorVersion & " Build " & (m_udtVersionInfo.dwBuildNumber And &HFFFF&)End Function
Public Function GetSystemMinorVersion() As String
GetSystemMinorVersion = m_udtVersionInfo.dwMinorVersion & " Build " & (m_udtVersionInfo.dwBuildNumber And &HFFFF&)End Function
Public Function GetSystemBuildVersion() As Long
GetSystemBuildVersion = (m_udtVersionInfo.dwBuildNumber And &HFFFF&)End Function
Private Sub Class_Initialize()
InitializeSystemInfo
End Sub
好象是把,反正是E开头的函数,可以实现部分功能,如果要求不搞,可以考虑用这个!
Imports System.Environment
Public Module modmain
Sub Main()
'The KPD-Team 2001
'URL: http://www.allapi.net/dotnet/
'E-Mail: [email protected]
Console.WriteLine("Operating System Platform ID: " _
+ OSVersion.Platform.ToString)
Console.WriteLine("Version: " + _
OSVersion.Version.Major.ToString + "." _
+ OSVersion.Version.Minor.ToString)
End Sub
End Module
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
wServicePackMajor As Integer
wServicePackMinor As Integer
wSuiteMask As Integer
wProductType As String
wReserved As String
End Type
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFOEX) As Long
Private Const VER_PLATFORM_WIN32s = 0
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2Private Const VER_SUITE_BACKOFFICE = 0 'Microsoft BackOffice components are installed.
Private Const VER_SUITE_BLADE = 1 'Windows .NET Web Server is installed.
Private Const VER_SUITE_DATACENTER = 2 ' Windows 2000 or Windows .NET Datacenter Server is installed.
Private Const VER_SUITE_ENTERPRISE = 3 ' Windows 2000 Advanced Server or Windows .NET Enterprise Server is installed.
Private Const VER_SUITE_PERSONAL = 4 ' Windows XP Home Edition is installed.
Private Const VER_SUITE_SMALLBUSINESS = 5 ' Microsoft Small Business Server is installed.
Private Const VER_SUITE_SMALLBUSINESS_RESTRICTED = 6 ' Microsoft Small Business Server is installed with the restrictive client license in force.
Private Const VER_SUITE_TERMINAL = 7 ' Terminal Services is installed.Private Const VER_NT_WORKSTATION = 0 'The system is running Windows NT 4.0 Workstation, Windows 2000 Professional, Windows XP Home Edition, or Windows XP Professional.
Private Const VER_NT_DOMAIN_CONTROLLER = 1 'The system is a domain controller.
Private Const VER_NT_SERVER = 2 'The system is a server.Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Const SM_CLEANBOOT = 67
Private Const SM_DEBUG = 22
Private Const SM_SLOWMACHINE = 73Private m_udtVersionInfo As OSVERSIONINFOEX
Private m_blnRet As BooleanPublic Enum enumSystemStatus
ssNormal = 0 '"正常模式"
ssSafeMode = 1 '"安全模式"
ssSafeModeWithNetwork = 2 '"带网络支持的安全模式"
ssDebug = 3 '"Windows 排错模式"
ssSlowMachine = 4 '"这台机器太慢以致不能流畅的运行Windows"
End EnumPublic Enum enumSystemPlatform
spWin32 = 0
spWindows = 1
spWinNT = 2
End EnumPrivate Sub InitializeSystemInfo()
m_udtVersionInfo.dwOSVersionInfoSize = 148
m_blnRet = CBool(GetVersionEx(m_udtVersionInfo))
End Sub
Public Function GetSystemPlatform() As enumSystemPlatform
Select Case m_udtVersionInfo.dwPlatformId
Case VER_PLATFORM_WIN32_WINDOWS
GetSystemPlatform = spWindows
Case VER_PLATFORM_WIN32_NT
GetSystemPlatform = spWinNT
Case Else
GetSystemPlatform = spWin32
End Select
End Function
Public Function GetSystemVersionEx() As String
With m_udtVersionInfo
Select Case .dwPlatformId
Case VER_PLATFORM_WIN32_WINDOWS
If .dwMajorVersion = 4 & .dwMinorVersion = 0 Then
GetSystemVersionEx = "Microsoft Windows 95"
If Mid(.szCSDVersion, 1, 1) = "C" Or Mid(.szCSDVersion, 1, 1) = "B" Then
GetSystemVersionEx = GetSystemVersionEx & " OSR2"
End If
ElseIf .dwMajorVersion = 4 And .dwMinorVersion = 10 Then
GetSystemVersionEx = "Microsoft Windows 98"
If Mid(.szCSDVersion, 1, 1) = "A" Then
GetSystemVersionEx = GetSystemVersionEx & " SE"
End If
ElseIf .dwMajorVersion = 4 And .dwMinorVersion = 90 Then
GetSystemVersionEx = "Microsoft Windows Millennium Edition"
Else
End If
Case VER_PLATFORM_WIN32_NT
If .dwMajorVersion <= 4 Then
GetSystemVersionEx = "Microsoft Windows NT"
ElseIf .dwMajorVersion = 5 And .dwMinorVersion = 0 Then
GetSystemVersionEx = "Microsoft Windows 2000"
Else
If m_blnRet Then
If .wProductType = VER_NT_WORKSTATION Then If .dwMajorVersion = 5 And .dwMinorVersion = 1 Then
GetSystemVersionEx = "Microsoft Windows XP" ElseIf .wSuiteMask And VER_SUITE_PERSONAL Then
GetSystemVersionEx = "Home Edition"
Else
GetSystemVersionEx = "Professional"
End If
ElseIf .wProductType = VER_NT_SERVER Then
If .dwMajorVersion = 5 And .dwMinorVersion = 1 Then
GetSystemVersionEx = "Microsoft Windows .NET"
ElseIf .wSuiteMask And VER_SUITE_DATACENTER Then
GetSystemVersionEx = "DataCenter Server"
ElseIf .wSuiteMask And VER_SUITE_ENTERPRISE Then
If .dwMajorVersion = 4 Then
GetSystemVersionEx = "Advanced Server"
Else
GetSystemVersionEx = "Enterprise Server"
End If
ElseIf .wSuiteMask = VER_SUITE_BLADE Then
GetSystemVersionEx = "Web Server"
Else
GetSystemVersionEx = "Server"
End If
Else
End If
Else
End If
End If
Case Else
End Select
End With
End Function
Public Function GetSystemStatus() As enumSystemStatus If GetSystemMetrics(SM_CLEANBOOT) = 0 Then
GetSystemStatus = ssNormal '"正常模式"
ElseIf GetSystemMetrics(SM_CLEANBOOT) = 1 Then
GetSystemStatus = ssSafeMode '= "安全模式"
ElseIf GetSystemMetrics(SM_CLEANBOOT) = 2 Then
GetSystemStatus = ssSafeModeWithNetwork '"带网络支持的安全模式"
ElseIf GetSystemMetrics(SM_DEBUG) Then
GetSystemStatus = ssDebug '"Windows 排错模式"
ElseIf GetSystemMetrics(SM_SLOWMACHINE) Then
GetSystemStatus = ssSlowMachine '"这台机器太慢以致不能流畅的运行Windows"
End IfEnd Function
Public Function GetSystemMajorVersion() As String
GetSystemMajorVersion = m_udtVersionInfo.dwMajorVersion '& "." & m_udtVersionInfo.dwMinorVersion & " Build " & (m_udtVersionInfo.dwBuildNumber And &HFFFF&)End Function
Public Function GetSystemMinorVersion() As String
GetSystemMinorVersion = m_udtVersionInfo.dwMinorVersion & " Build " & (m_udtVersionInfo.dwBuildNumber And &HFFFF&)End Function
Public Function GetSystemBuildVersion() As Long
GetSystemBuildVersion = (m_udtVersionInfo.dwBuildNumber And &HFFFF&)End Function
Private Sub Class_Initialize()
InitializeSystemInfo
End Sub参考:
http://msdn.microsoft.com/library/en-us/sysinfo/sysinfo_92jy.asp?frame=true
非常可惜,能诉我如何使用吗?
新建一个类模块,命名为cSystemVersionInfo使用:先声明:private m_ucmSystemVersionInfo as new cSystemVersionInfo获取具体系统版本信息:msgbox m_ucmSystemVersionInfo.GetSystemVersionEx