• 取得Computer Name, OS的版本

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
End Type

Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
        (lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Function GetComputerName Lib "kernel32" Alias _
        "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Const VER_PLATFORM_WIN32_NT = 2
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32s = 0

Private Sub Command1_Click()
Dim len5 As Long, aa As Long
Dim cmprName As String
Dim osver As OSVERSIONINFO

'取得Computer Name
cmprName = String(255, 0)
len5 = 256
aa = GetComputerName(cmprName, len5)
cmprName = Left(cmprName, InStr(1, cmprName, Chr(0)) - 1)
Debug.Print "Computer Name = "; cmprName

'取得OS的版本
osver.dwOSVersionInfoSize = Len(osver)
aa = GetVersionEx(osver)
Debug.Print "MajorVersion "; osver.dwMajorVersion
Debug.Print "MinorVersion "; osver.dwMinorVersion

Select Case osver.dwPlatformId
Case ER_PLATFORM_WIN32s
    Debug.Print "Microsoft Win32s "
Case VER_PLATFORM_WIN32_WINDOWS
    If (osver.dwMajorVersion = 4) And (osver.dwMinorVersion = 0) Then
         Debug.Print "Microsoft Windows 95 "
        If (Mid(osver.szCSDVersion, 2, 1) = "C") Then
            Debug.Print ; "OSR2 "
        End If
    ElseIf (osver.dwMajorVersion = 4) And (osver.dwMinorVersion = 10) Then
        If Mid(osver.szCSDVersion, 2, 1) = "A" Then
            Debug.Print "Microsoft Windows 98 SE"
        Else
            Debug.Print "Microsoft Windows 98"
        End If

    ElseIf (osver.dwMajorVersion = 4) And (osver.dwMinorVersion = 90) Then
        Debug.Print ("Microsoft Windows Me ");
    End If
Case VER_PLATFORM_WIN32_NT
    If osver.dwMajorVersion <= 4 Then
            Debug.Print "Microsoft Windows NT "

    ElseIf (osver.dwMajorVersion = 5) And (osver.dwMinorVersion) = 0 Then
            Debug.Print "Microsoft Windows 2000 "

    ElseIf (osver.dwMajorVersion = 5) And (osver.dwMinorVersion = 1) Then
            Debug.Print "Windows XP"
    End If
End Select
End Sub
 

  • 相關資訊

  GetVersionEx

  GetUserName

  GetVersion

  Getting the System Version

  Operating System Version

  System Information Overview

  System Information Functions

  • 文件出處

  cww

  Honey增訂

VB心得筆記歡迎各位的指教,如果您有任何文章或資料願意提供給我們的,請來信到VBNote

如果對本站有任何建議,歡迎來信給Honey,我們會盡快給您答覆