' By chijanzen
Private Declare Function GetVersionExA Lib "kernel32" _
(lpVersionInformation As OSVERSIONINFO) As Long
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long ' 此一資料結構的大小
dwMajorVersion As Long ' 版本主編號, 例如 4.0.950 的 4
dwMinorVersion As Long ' 版本次編號, 例如 4.0.950 的 0
dwBuildNumber As Long ' 版本建立編號, 例如 4.0.950 的 950
dwPlatformId As Long ' 作業平臺
szCSDVersion As String * 128 ' 版本的進一步說明
End Type
Public lpVersionInformation As OSVERSIONINFO
'VER_PLATFORM_WIN32s(= 0) Win32s, 可在 Win 3.1 底下執行 32 位元元應用程式的平臺
'VER_PLATFORM_WIN32_Windows(= 1) Windows 95 或 98
'VER_PLATFORM_WIN32_NT(= 2) Windows NT 或 200 或 XP
Sub ShowWVersion()
Dim s As String, a As String
a = OperatingSystem
Select Case a
Case 0: s = "Windows 32"
Case 1: s = "Windows 95"
Case 2: s = "Windows 98"
Case 3: s = "Windows ME"
Case 4: s = "Windows NT"
Case 5: s = "Windows 2000"
Case 6: s = "Windows XP"
End Select
MsgBox s
End Sub
Sub test()
MsgBox Application.OperatingSystem
End Sub
Public Function OperatingSystem() As Integer
lpVersionInformation.dwOSVersionInfoSize = Len(lpVersionInformation)
Call GetVersionExA(lpVersionInformation)
If (lpVersionInformation.dwPlatformId = 0) Then 'VER_PLATFORM_WIN32s(= 0) Win32s _
,可在 Win 3.1 底下執行 32 位元元應用程式的平臺
OperatingSystem = 0
ElseIf (lpVersionInformation.dwPlatformId = 1) And _
(lpVersionInformation.dwMinorVersion = 0) Then 'Win95:VER_PLATFORM_WIN32_Windows(= 1) _
dwMinorVersion = 0
OperatingSystem = 1
ElseIf (lpVersionInformation.dwPlatformId = 1) And _
(lpVersionInformation.dwMinorVersion = 10) Then 'Win98:VER_PLATFORM_WIN32_Windows(= 1) _
dwMinorVersion = 10
OperatingSystem = 2
ElseIf (lpVersionInformation.dwPlatformId = 1) And _
(lpVersionInformation.dwMinorVersion = 90) Then 'WinMe:VER_PLATFORM_WIN32_Windows(= 1) _
dwMinorVersion = 90
OperatingSystem = 3
ElseIf (lpVersionInformation.dwPlatformId = 2) And _
(lpVersionInformation.dwMajorVersion < 5) Then 'WinNT:VER_PLATFORM_WIN32_Windows(= 1) _
dwMinorVersion < 5
OperatingSystem = 4
ElseIf (lpVersionInformation.dwPlatformId = 2) And _
(lpVersionInformation.dwMajorVersion = 5) And _
(lpVersionInformation.dwMinorVersion = 0) Then 'Win2000:VER_PLATFORM_WIN32_Windows(= 1) _
dwMinorVersion=5 and dwMinorVersion = 0
OperatingSystem = 5
ElseIf (lpVersionInformation.dwPlatformId = 2) And _
(lpVersionInformation.dwMajorVersion = 5) And _
(lpVersionInformation.dwMinorVersion = 1) Then 'WinXP:VER_PLATFORM_WIN32_Windows(= 1) _
dwMinorVersion=5 and dwMinorVersion = 0
OperatingSystem = 6
End If
End Function
联系客服