Private Sub Form_Load()
Dim strComputer, objWMIService, colItems, objItem, strOSversion As String
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" &strComputer &"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objItem In colItems
strOSversion = objItem.Version
Next
Select Case Left(strOSversion, 3)
Case "5.2"
strOSversion = "Windows Server 2003"
Case "5.0"
strOSversion = "Windows 2000"
Case "5.1"
strOSversion = "Windows XP"
Case "6.0"
strOSversion = "windows visita"
Case Else
strOSversion = "i don't know"
End Select
Me.AutoRedraw = True
Me.Cls
Print "你的 *** 作系统是:" &strOSversion
End Sub
function GetWindowsVersion: stringvar
Info: OSVERSIONINFO
begin
FillChar(Info, sizeof(Info), 0)
Info.dwOSVersionInfoSize := sizeof(OSVERSIONINFO)
GetVersionEx(Info)
end
//完全没问题,我的是win8 ,取的版本号是6.2.9200
用win32 API GetVersionEx需要的结构:
Public 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
End Type
声明
Public Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
用法见百科,不过百科里那个声明有误,把参数前的Byval去掉
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)