如何獲得 Windows 作業系統的版本

來源:互聯網
上載者:User

標籤:style   color   c   int   get   com   

如何獲得 Windows 作業系統的版本

很多時候我們需要知道Windows作業系統的版本,使用下面這個API函數可以做到。

Option Explicit

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 ‘ Maintenance string for PSS usage 
osName As String ‘ 我自己加的, 作業系統的名稱 
End Type

‘ 獲得 Windows 作業系統的版本 
‘ OSVERSIONINFO 結構中的 osName 返回作業系統的名稱 
Private Function GetWindowsVersion() As OSVERSIONINFO 
Dim ver As OSVERSIONINFO 
ver.dwOSVersionInfoSize = 148 
GetVersionEx ver 
With ver 
Select Case .dwPlatformId 
Case 1 
Select Case .dwMinorVersion 
Case 0 
.osName = "Windows 95" 
Case 10 
.osName = "Windows 98" 
Case 90 
.osName = "Windows Mellinnium" 
End Select 
Case 2 
Select Case .dwMajorVersion 
Case 3 
.osName = "Windows NT 3.51" 
Case 4 
.osName = "Windows NT 4.0" 
Case 5 
Select Case .dwMinorVersion 
Case 0 
.osName = "Windows 2000" 
Case 1 
.osName = "Windows XP" 
Case 2 
.osName = "Windows Server 2003" 
End Select 
End Select 
Case Else 
.osName = "Failed" 
End Select 
End With 
GetWindowsVersion = ver 
End Function

Private Sub Command1_Click() 
Dim ver As OSVERSIONINFO 
ver = GetWindowsVersion() 
With ver 
Debug.Print .osName, .dwMajorVersion, .dwMinorVersion, .dwBuildNumber, .dwPlatformId, .szCSDVersion 
End With 
End Sub

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.