api: GetVersion ()VB声明 Declare Function GetVersion Lib "kernel32" Alias "GetVersion" () As Long 说明 判断当前运行的Windows和DOS版本 返回值 Long,低16位包含了windows版本;低字节包含了主版本号(3代表windows 3.10,4代表nt 4.0);高字节包含了两个数位的辅助版本号(10代表windows 3.10,95代表windows 95)。高16位则包含了平台信息。针对windows NT,高位设为0;针对windows for workgroups上运行的Win32s,则高位为1 注解 在win32下,最好换用GetVersionEx函数。在win32下,高字不会返回DOS版本
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long Private Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type Private Sub Form_Load() Dim OSInfo As OSVERSIONINFO, PId As String Me.AutoRedraw = True OSInfo.dwOSVersionInfoSize = Len(OSInfo) Ret& = GetVersionEx(OSInfo) If Ret& = 0 Then MsgBox "Error Getting Version Information": Exit Sub Select Case OSInfo.dwPlatformId Case 0 PId = "Windows 32s " Case 1 PId = "Windows 95/98" Case 2 PId = "Windows NT " End Select Print "OS: " + PId Print "Win version:" + Str$(OSInfo.dwMajorVersion) + "." + LTrim(Str(OSInfo.dwMinorVersion)) Print "Build: " + Str(OSInfo.dwBuildNumber) End Sub
GetVersion ()VB声明
Declare Function GetVersion Lib "kernel32" Alias "GetVersion" () As Long
说明
判断当前运行的Windows和DOS版本
返回值
Long,低16位包含了windows版本;低字节包含了主版本号(3代表windows 3.10,4代表nt 4.0);高字节包含了两个数位的辅助版本号(10代表windows 3.10,95代表windows 95)。高16位则包含了平台信息。针对windows NT,高位设为0;针对windows for workgroups上运行的Win32s,则高位为1
注解
在win32下,最好换用GetVersionEx函数。在win32下,高字不会返回DOS版本
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type
Private Sub Form_Load()
Dim OSInfo As OSVERSIONINFO, PId As String
Me.AutoRedraw = True
OSInfo.dwOSVersionInfoSize = Len(OSInfo)
Ret& = GetVersionEx(OSInfo)
If Ret& = 0 Then MsgBox "Error Getting Version Information": Exit Sub
Select Case OSInfo.dwPlatformId
Case 0
PId = "Windows 32s "
Case 1
PId = "Windows 95/98"
Case 2
PId = "Windows NT "
End Select
Print "OS: " + PId
Print "Win version:" + Str$(OSInfo.dwMajorVersion) + "." + LTrim(Str(OSInfo.dwMinorVersion))
Print "Build: " + Str(OSInfo.dwBuildNumber)
End Sub