VB 6.0 获取操作系统的名称及版本源码(模块)
生活随笔
收集整理的這篇文章主要介紹了
VB 6.0 获取操作系统的名称及版本源码(模块)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
VB 6.0 獲取操作系統(tǒng)的名稱及版本源碼(模塊)
發(fā)現(xiàn)博客園插入代碼的列表里面沒有VB一項(xiàng),只有VB.NET。。。
前幾天用VB寫的一個(gè)獲取網(wǎng)卡相關(guān)信息時(shí)用到的,收藏下,說不定以后還用得到!
其實(shí)最簡單的方法就是讀取環(huán)境變量里面的“OS”,即:Environ("OS"),但這樣獲取的值不準(zhǔn)確,所以就有了下面這種方法:
Option Explicit
Public OSName As String '操作系統(tǒng)名稱(簡稱),方便程序控制時(shí)根據(jù)操作系統(tǒng)取值
Public Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
wServicePackMajor As Integer
wServicePackMinor As Integer
wSuiteMask As Integer
wProductType As Byte
wReserved As Byte
End Type
Public Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
' 獲得 Windows 操作系統(tǒng)的名稱,returnType決定返回的方式,值為0時(shí),返回簡稱,否則返回全稱
Public Function GetWindowsVersion(ByVal returnType As Integer) As String
Dim ver As OSVERSIONINFO, retLng As Long, os As String
ver.dwOSVersionInfoSize = Len(ver)
GetVersionEx ver
' retLng = GetVersionEx(ver)
' If retLng = 0 Then
' os = "Unknown System Version!"
' Exit Function
' End If
With ver
Select Case .dwPlatformId
Case 1
Select Case .dwMinorVersion
Case 0
If returnType = 0 Then
os = "Windows 95"
Else
Select Case .szCSDVersion
Case "C"
os = "Windows 95 OSR2"
Case "B"
os = "Windows 95 OSR2"
Case Else
os = "Windows 95"
End Select
End If
Case 10
If returnType = 0 Then
os = "Windows 98"
Else
Select Case .szCSDVersion
Case "A"
os = "Windows 98 SE"
Case Else
os = "Windows 98"
End Select
End If
Case 90
If returnType = 0 Then
os = "Windows Me"
Else
os = "Windows Millennium Edition"
End If
End Select
Case 2
Select Case .dwMajorVersion
Case 3
os = "Windows NT 3.51"
Case 4
os = "Windows NT 4.0"
Case 5
Select Case .dwMinorVersion
Case 0
If returnType = 0 Then
os = "Windows 2000"
Else
Select Case .wSuiteMask
Case &H80
os = "Windows 2000 Data center"
Case &H2
os = "Windows 2000 Advanced"
Case Else
os = "Windows 2000"
End Select
End If
Case 1
If returnType = 0 Then
os = "Windows XP"
Else
Select Case .wSuiteMask
Case &H0
os = "Windows XP Professional"
Case &H200
os = "Windows XP Home"
Case Else
os = "Windows XP"
End Select
End If
Case 2
If returnType = 0 Then
os = "Windows Server 2003"
Else
Select Case .wSuiteMask
Case &H2
os = "Windows Server 2003 Enterprise"
Case &H80
os = "Windows Server 2003 Data center"
Case &H400
os = "Windows Server 2003 Web Edition"
Case &H0
os = "Windows Server 2003 Standard"
' Case &H112
' os = "Windows Server 2003 R2 Enterprise"
Case Else
os = "Windows Server 2003"
End Select
End If
End Select
If returnType <> 0 And .wServicePackMajor > 0 Then
os = os & " Service Pack " & .wServicePackMajor & IIf(.wServicePackMinor > 0, "." & .wServicePackMinor, vbNullString)
End If
Case 6
If returnType <> 0 Then
Select Case .wProductType
Case &H6
os = "Business Edition"
Case &H10
os = "Business Edition (N)"
Case &H12
os = "Cluster Server Edition"
Case &H8
os = "Server Datacenter Edition (full installation)"
Case &HC
os = "Server Datacenter Edition (core installation)"
Case &H4
os = "Enterprise Edition"
Case &H1B
os = "Enterprise Edition (N)"
Case &HA
os = "Server Enterprise Edition (full installation)"
Case &HE
os = "Server Enterprise Edition (core installation)"
Case &HF
os = "Server Enterprise Edition for Itanium-based Systems"
Case &H2
os = "Home Basic Edition"
Case &H5
os = "Home Basic Edition (N)"
Case &H3
os = "Home Premium Edition"
Case &H1A
os = "Home Premium Edition (N)"
Case &H13
os = "Home Server Edition"
Case &H18
os = "Server for Small Business Edition"
Case &H9
os = "Small Business Server"
Case &H19
os = "Small Business Server Premium Edition"
Case &H7
os = "Server Standard Edition (full installation)"
Case &HD
os = "Server Standard Edition (core installation)"
Case &H8
os = "Starter Edition"
Case &H17
os = "Storage Server Enterprise Edition"
Case &H14
os = "Storage Server Express Edition"
Case &H15
os = "Storage Server Standard Edition"
Case &H16
os = "Storage Server Workgroup Edition"
Case &H1
os = "Ultimate Edition"
Case &H1C
os = "Ultimate Edition (N)"
Case &H0
os = "An unknown product"
Case &HABCDABCD
os = "Not activated product"
Case &H11
os = "Web Server Edition"
End Select
End If
Select Case .dwMinorVersion
Case 0
Select Case .wProductType
Case 3
If returnType = 0 Then
os = "Windows Server 2008"
Else
os = "Windows Server 2008 " & os
End If
Case Else
If returnType = 0 Then
os = "Windows Vista"
Else
os = "Windows Vista " & os
End If
End Select
Case 1
Select Case .wProductType
Case 3
If returnType = 0 Then
os = "Windows Server 2008 R2"
Else
os = "Windows Server 2008 R2" & os
End If
Case Else
If returnType = 0 Then
os = "Windows 7"
Else
os = "Windows 7 " & os
End If
End Select
End Select
If returnType <> 0 And .wServicePackMajor > 0 Then
os = os & " Service Pack " & .wServicePackMajor & IIf(.wServicePackMinor > 0, "." & .wServicePackMinor, vbNullString)
End If
End Select
Case Else
os = "Unknown System Version!"
End Select
If returnType <> 0 Then os = os & " [Version: " & .dwMajorVersion & "." & .dwMinorVersion & "." & .dwBuildNumber & "]"
End With
GetWindowsVersion = os
End Function
'返回獲取本地連接屬性的方式
'Vista及Win7下 GetDetailsOf(FolderItem, 2) 獲取的值類似于:“Marvell Yukon 88E8056 PCI-E Gigabit Ethernet Controller”,對(duì)應(yīng)XP、2000及2003下的GetDetailsOf(FolderItem, 3)
'Vista及Win7下 GetDetailsOf(FolderItem, 1) 獲取的值為本地連接狀態(tài),為“網(wǎng)絡(luò)”時(shí)說明正常,對(duì)應(yīng)XP、2000及2003下的GetDetailsOf(FolderItem, 2)
Public Function getAdapterStatusType() As Integer
Select Case OSName
Case "Windows Vista", "Windows Server 2008", "Windows 7", "Windows Server 2008 R2"
getAdapterStatusType = 2
Case Else
getAdapterStatusType = 3
End Select
End Function
總結(jié)
以上是生活随笔為你收集整理的VB 6.0 获取操作系统的名称及版本源码(模块)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 华为RH2288H服务器引导Servic
- 下一篇: 【网站支付PHP篇】thinkPHP集成