怎样利用GetVersion函数来判断当前 *** 作系统是Win9598、Win2000XP、VistaWin7呢?

怎样利用GetVersion函数来判断当前 *** 作系统是Win9598、Win2000XP、VistaWin7呢?,第1张

这个网上搜的,不是用API,用VB的GetObject直接判断 *** 作系统

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: string

    var

      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去掉


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/6688041.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-26
下一篇 2023-03-26

发表评论

登录后才能评论

评论列表(0条)

保存