怎样利用GetVersion函数来判断当前操作系统是Win95/98、Win2000/XP、Vista/Win7呢?
以下这个获得视窗操作系统版本的函数是通过GetVersion这个早期API实现的,可以判断返回当前系统是Win2000 or WinXP还是Windows ME。那么请问怎样修改才能使他进一步完善一些,能够判断Win95/98、WinME、Win2000/XP、Vista/Win7呢?
由于我这儿没装虚拟机,也没第二台机子作测试,麻烦哪位朋友弄过这个帮我修改一下吧,那个低位高位换算得我看不懂
也搜过网上不少示例,但几乎都是通过GetVersionEx实现的,而我就想用这个古老的GetVersion实现……
Private Function GetWinVersion() As String
Dim lngRetval, lngMajor, lngMinor As Long
lngRetval = GetVersion()
lngMinor = (lngRetval And &HFF00) \ &H100
lngMajor = (lngRetval And &HFF)
If CBool((lngRetval And &H80000000) = 0&) Then
If CBool(lngMajor >= 5&) Then
'Win2000 or WinXP
GetWinVersion = "Win2000 or WinXP"
Else
End If
ElseIf CBool(lngMajor = 4&) And CBool(lngMinor = 90&) Then
'Windows ME
GetWinVersion = "Windows ME"
Else
End If
End Function
Private Function GetWinVersion() As String
Dim lngRetval, lngMajor, lngMinor As Long
lngRetval = GetVersion()
lngMinor = (lngRetval And &HFF00&) \ &H100
lngMajor = (lngRetval And &HFF)
If CBool((lngRetval And &H80000000) = 0&) Then
If lngMajor = 6 And lngMinor = 1 Then GetWinVersion = "windows 7"
If lngMajor = 6 And lngMinor = 0 Then GetWinVersion = "windows vista"
If lngMajor = 5 And lngMinor = 1 Then GetWinVersion = "windows xp"
If lngMajor = 5 And lngMinor = 0 Then GetWinVersion = "windows 2000"
ElseIf CBool(lngMajor = 4&) And CBool(lngMinor = 90&) Then
'Windows ME
GetWinVersion = "Windows ME"
Else
End If
End Function
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformID As Long
szCSDVersion As String * 128
End Type
Public OsName$, TmpStr$, Ary
Private Sub Form_Activate()
Ary = Array("", "Windows 95", "Windows 98", "Windows Me", "Windows NT4.0", "Windows 2000", "Windows XP", "Windows 2003", "Windows Vista", "Windows 7")
MsgBox "您的操作系统是:" & Ary(GetVersion)
End Sub
Public Function GetVersion() As Long
Dim OSInfo As OSVERSIONINFO
Call GetVersionEx(OSInfo)
OSInfo.dwOSVersionInfoSize = 148
OSInfo.szCSDVersion = Space(128)
Call GetVersionEx(OSInfo)
Select Case OSInfo.dwPlatformID
Case VER_PLATFORM_WIN32s
OsName = "Windows 3.1"
Case VER_PLATFORM_WIN32_WINDOWS
OsName = "Windows 98"
Case VER_PLATFORM_WIN32_NT
OsName = "Windows NT"
End Select
TmpStr = OsName & "(" & OSInfo.dwMajorVersion & "." & OSInfo.dwMinorVersion & ")"
If InStr(TmpStr$, "95") Then GetVersion = 1: Exit Function
If InStr(TmpStr$, "98") Then GetVersion = 2: Exit Function
If InStr(TmpStr$, "Me") Then GetVersion = 3: Exit Function
If InStr(TmpStr$, "4.0") Then GetVersion = 4: Exit Function
If InStr(TmpStr$, "5.0") Then GetVersion = 5: Exit Function
If InStr(TmpStr$, "5.1") Then GetVersion = 6: Exit Function
If InStr(TmpStr$, "5.2") Then GetVersion = 7: Exit Function
If InStr(TmpStr$, "6.0") Then GetVersion = 8: Exit Function
If InStr(TmpStr$, "6.1") Then GetVersion = 9
End Function
[解决办法]
获取Windows操作系统所有版本
http://www.mndsoft.com/blog/VB6/0964.html