Results 1 to 12 of 12

Thread: Help!! Need to determine OS

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    2
    Is these an API call to return the type of OS is running,
    i.e. Windows NT or Windows 98? I would greatly appreciate any help. Thanks in advance...

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Code:
    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
    End Type
    Private Sub Form_Load()
        Dim OSInfo As OSVERSIONINFO, PId As String
        'Set the graphical mode to persistent
        Me.AutoRedraw = True
        'Set the structure size
        OSInfo.dwOSVersionInfoSize = Len(OSInfo)
        'Get the Windows version
        Ret& = GetVersionEx(OSInfo)
        'Chack for errors
        If Ret& = 0 Then MsgBox "Error Getting Version Information": Exit Sub
        'Print the information to the form
        Select Case OSInfo.dwPlatformId
            Case 0
                PId = "Windows 32s "
            Case 1
                PId = "Windows 95/98"
            Case 2
                PId = "Windows NT "
        End Select
        Print "OS: " + PId
        Print "Win version:" + str$(OSInfo.dwMajorVersion) + "." + LTrim(str(OSInfo.dwMinorVersion))
        Print "Build: " + str(OSInfo.dwBuildNumber)
    End Sub
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Guest
    If PId = 0 then it should be Windows 3.x

  4. #4
    Addicted Member
    Join Date
    Nov 2000
    Posts
    143
    You can also get this information w. RegOpenKeyEx .
    Path is
    HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS\CURRENT VERSION\
    keys = Product Version
    Product Name
    Version number
    etc.



  5. #5
    Addicted Member overhill's Avatar
    Join Date
    Mar 2000
    Location
    KS, United States
    Posts
    181
    Using the code that Vlatko provided, what does Windows ME return? Is it the same as Windows 95/98?

  6. #6
    Guest
    Yes

  7. #7
    Guest
    By using the method Help gave you, you can be even more specific with regard to what your product is. For example, if pID = 1 then you are not sure whether it's Win95, 98 or ME, whereas the registry method will specify what version it is.

  8. #8
    Guest
    Here is some code that corrosponds to Help's method.

    Add to a Module
    Code:
    Declare Function RegCloseKey Lib "advapi32.dll" (ByVal HKEY As Long) As Long
    Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal HKEY As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal HKEY As Long, ByVal lpSubKey As String) As Long
    Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal HKEY As Long, ByVal lpValueName As String) As Long
    Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal HKEY As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal HKEY As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
    Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal HKEY As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
    Public Const HKEY_CLASSES_ROOT = &H80000000
    Public Const HKEY_CURRENT_USER = &H80000001
    Public Const HKEY_LOCAL_MACHINE = &H80000002
    Public Const HKEY_USERS = &H80000003
    Public Const HKEY_PERFORMANCE_DATA = &H80000004
    Public Const REG_SZ = 1
    
    Function RegQueryStringValue(ByVal HKEY As Long, ByVal strValueName As String)
        Dim lResult As Long
        Dim lValueType As Long
        Dim strBuf As String
        Dim lDataBufSize As Long
        
        On Error GoTo 0
        lResult = RegQueryValueEx(HKEY, strValueName, 0&, lValueType, ByVal 0&, lDataBufSize)
        If lResult = ERROR_SUCCESS Then
            If lValueType = REG_SZ Then
                strBuf = String(lDataBufSize, " ")
                lResult = RegQueryValueEx(HKEY, strValueName, 0&, 0&, ByVal strBuf, lDataBufSize)
                If lResult = ERROR_SUCCESS Then
                    RegQueryStringValue = StripTerminator(strBuf)
                End If
            End If
        End If
    End Function
    
    Public Function GetSettingEx(HKEY As Long, sPath As String, sValue As String)
        Dim KeyHand&
        Dim datatype&
        Call RegOpenKey(HKEY, sPath, KeyHand&)
        GetSettingEx = RegQueryStringValue(KeyHand&, sValue)
        Call RegCloseKey(KeyHand&)
    End Function
    
    Function StripTerminator(ByVal strString As String) As String
        Dim intZeroPos As Integer
    
        intZeroPos = InStr(strString, Chr$(0))
        If intZeroPos > 0 Then
            StripTerminator = Left$(strString, intZeroPos - 1)
        Else
            StripTerminator = strString
        End If
    End Function
    
    Public Sub SaveSettingEx(HKEY As Long, sPath As String, sValue As String, sData As String)
        Dim KeyHand As Long
        Call RegCreateKey(HKEY, sPath, KeyHand)
        Call RegSetValueEx(KeyHand&, sValue, 0, REG_SZ, ByVal sData, Len(sData))
        Call RegCloseKey(KeyHand&)
    End Sub
    Code for a Form.
    Code:
    Private Sub Command1_Click()
    
        Dim sWinName As String
        sWinName = GetSettingEx(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion", "ProductName")
        
        MsgBox "You are running " & sWinName
    End Sub

  9. #9
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Question

    Meg, I can't get this in WinNT platform. Why?

    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\ProductName

  10. #10
    Hyperactive Member PJB's Avatar
    Join Date
    Aug 2000
    Location
    dunno at the moment
    Posts
    302
    I got it to work on Windows 2000 by changing it to this:
    Code:
    (HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows NT\CurrentVersion", "ProductName")
    VB6.0 SP4
    Windows 2000
    I'm thinking of a number between

  11. #11
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Thanks PJB, it great. Finally I learn somethings new from Help and you. )

  12. #12
    Hyperactive Member PJB's Avatar
    Join Date
    Aug 2000
    Location
    dunno at the moment
    Posts
    302
    always happy to help a pompous ass , but all i did was plug the NT into what Megatron posted, so if you want to thank someone why not thank him for helping someone of your greatness
    VB6.0 SP4
    Windows 2000
    I'm thinking of a number between

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width