说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

VB获取当前系统平台

HTML文档下载 WORD文档下载 PDF文档下载
VB获取当前系统平台
有些程序只能在Win9x下运行,有些程序只能在Winnt下运行,因此我们有时需要判断当前的系统的平台. 下面的程序可以实现该功能:
>>步骤1----建立新工程,在窗体上放置一个CommandButton按钮.
>>步骤2----添加下列代码:

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 Declare Function GetVersionEx Lib "kernel32" Alias _
"GetVersionExA" (lpVersionInformation As _
OSVERSIONINFO) As Boolean

Private Const VER_PLATFORM_WIN32s = 0
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2

Private Sub Command1_Click()
Dim Ver As OSVERSIONINFO
Ver.dwOSVersionInfoSize = Len(Ver)
Call GetVersionEx(Ver)
If Ver.dwPlatformId = 0 Then
MsgBox "Win32"
ElseIf Ver.dwPlatformId = 1 Then
MsgBox "Win95,Win98"
ElseIf Ver.dwPlatformId = 2 Then
MsgBox "Winnt"
Else
MsgBox "Error"
End If
End Sub

>>步骤3----编译运行,按下Command1,可以查看平台信息.
备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘