CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    May 2013
    Posts
    5

    get opera version

    Hi guys,

    i have this piece of code to retrieve Opera version, but doesn't seems to work. works well for IE

    Public Function GetOperaVersion$()
    Dim sOperaPath$, sOperaVer$, sOperaFriendlyVer$
    On Error GoTo Error:
    sOperaPath = RegGetString(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\App Paths\Opera.exe", "")
    If sOperaPath = "" Then GoTo EndOfFun:
    If FileExists(sOperaPath) = False Then GoTo EndOfFun:

    Dim hData&, lDataLen&, uBuf() As Byte, uVFFI As VS_FIXEDFILEINFO
    lDataLen = GetFileVersionInfoSize(sOperaPath, ByVal 0)
    If lDataLen = 0 Then
    GoTo EndOfFun:
    End If

    ReDim uBuf(0 To lDataLen - 1)
    'get handle to file props
    GetFileVersionInfo sOperaPath, 0, lDataLen, uBuf(0)
    VerQueryValue uBuf(0), "\", hData, lDataLen
    CopyMemory uVFFI, ByVal hData, Len(uVFFI)
    With uVFFI
    sOperaVer = Format(.dwFileVersionMSh, "00") & "." & _
    Format(.dwFileVersionMSl, "00") & "." & _
    Format(.dwProductVersionLSh, "0000")


    End With
    If sOperaVer = "00.00.0000" Then GoTo EndOfFun:

    EndOfFun:
    If lDataLen > 0 And Left(sOperaFriendlyVer, 1) <> "0" Then
    GetOperaVersion = "Opera v" & sOperaFriendlyVer & " (" & sOperaVer & ")"
    Else
    GetOperaVersion = "Unable to get Opera version!"
    End If
    Exit Function

    Error:
    ErrorMsg Err.Number, Err.Description, "GetOperaVersion"
    End Function
    do you see anything wrong? if you have a better way to do just let me know or a better idea
    thanks for the help

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: get opera version

    The header has the version # in it, I'd bet
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    May 2013
    Posts
    5

    Re: get opera version

    what do you mean?

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: get opera version

    Quote Originally Posted by dglienna View Post
    The header has the version # in it, I'd bet
    ? huh?

    Anyways temp0, I'd suggest looking in your Registry Editor for the path. I think it might be :
    H_KEY_LOCAL_MACHINE\Software\Opera Software
    Then update your code :

    Code:
    RegGetString(HKEY_LOCAL_MACHINE, "Software\Opera Software\Opera.exe", "")
    Opera is not a Windows Product. You are looking for a Windows product named Opera...

  5. #5
    Join Date
    May 2013
    Posts
    5

    Re: get opera version

    that key does exist HanneSThEGreaT. It is not a microsoft product but it is installed on windows. that key gives you the path where opera.exe is located. from there i wanna get the file information to determine the version.

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: get opera version

    Hi Temp0.

    OK, first, I didn't look closely enough at your initial Registry location that you are searching in, so I apologise.

    Anyways, your Registry location :

    Code:
    HKEY_LOCAL_MACHINE, "Software\Opera Software\Opera.exe"
    As well as mine :

    Code:
    HKEY_LOCAL_MACHINE, "Software\Opera Software\Opera.exe
    Only finds determines whether or not Opera is installed on the PC


    I downloaded Opera, which I have always loved, but since using FireFox, I kinda forgot about it

    I installed Opera, and searched the entire registry for all Opera occurrences.

    I eventually found this location :

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Opera 12.15.1748

    Inside there is strings to identify the Major and Minor versions as well.

    What you ned to do now is to look inside the "Uninstall" sub key for opera and just use a bit of string manipulation ( such as Right() or Mid() ) to get the version.

    Will you be able to do that?

    Otherwise just shout, and I'll see what I can come up with.

    I really hope this helps you now

  7. #7
    Join Date
    May 2013
    Posts
    5

    Re: get opera version

    Hi HanneSThEGreaT,

    Thanks for your reply. I had the same idea when i found that uninstall key but i was wondering how to be able to always find it as it will change for every version of Opera.
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Opera xx.xx.xxxx
    so this is why i preferred to go the other way by checking opera.exe file info and grab the version there.
    but if you have an easy to do so, you're welcome to share it. I'm not very familiar with string manip Right/Left.

  8. #8
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Cool Re: get opera version

    Hi Temp0.

    That key would be the best, as it shows us what we need.

    I quickly slammed something together for you :

    Code:
    Option Explicit
    
    Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
    Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
    Private Declare Function RegQueryValue Lib "advapi32.dll" Alias "RegQueryValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal lpValue As String, lpcbValue As Long) As Long
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    
    Private Const ERROR_SUCCESS = 0&
    
    Private Const HKEY_LOCAL_MACHINE = &H80000002
    
    Private Const STANDARD_RIGHTS_ALL = &H1F0000
    Private Const KEY_QUERY_VALUE = &H1
    Private Const KEY_SET_VALUE = &H2
    Private Const KEY_CREATE_SUB_KEY = &H4
    Private Const KEY_ENUMERATE_SUB_KEYS = &H8
    Private Const KEY_NOTIFY = &H10
    Private Const KEY_CREATE_LINK = &H20
    Private Const SYNCHRONIZE = &H100000
    Private Const KEY_ALL_ACCESS = _
        ((STANDARD_RIGHTS_ALL Or _
        KEY_QUERY_VALUE Or _
        KEY_SET_VALUE Or _
        KEY_CREATE_SUB_KEY Or _
        KEY_ENUMERATE_SUB_KEYS Or _
        KEY_NOTIFY Or KEY_CREATE_LINK) And _
        (Not SYNCHRONIZE))
    
    ' Get the key information for this key and
    ' its subkeys.
    Private Sub GetKeyInfo(ByVal key_name As String)
    Dim subkeys As Collection
    Dim subkey_num As Integer
    Dim subkey_name As String
    
    Dim length As Long
    Dim hKey As Long
    Dim txt As String
    
    Dim strOpera As String
    Dim strMajor As String
    Dim strMinor As String
    Dim intSpacePos As Integer
    
    strOpera = "Opera"
    
        Set subkeys = New Collection
          
        ' Open the key.
        If RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
            key_name, _
            0&, KEY_ALL_ACCESS, hKey) <> ERROR_SUCCESS _
        Then
            MsgBox "Error opening key."
            Exit Sub
        End If
        
        ' Enumerate the subkeys.
        subkey_num = 0
        Do
            ' Enumerate subkeys until we get an error.
            length = 256
            subkey_name = Space$(length)
            If RegEnumKey(hKey, subkey_num, _
                subkey_name, length) _
                    <> ERROR_SUCCESS Then Exit Do
            subkey_num = subkey_num + 1
            
            subkey_name = Left$(subkey_name, InStr(subkey_name, Chr$(0)) - 1)
            If InStr(1, subkey_name, "Opera") Then 'determine string Opera
            strOpera = subkey_name 'set strOpera to Opera key
                If InStr(1, subkey_name, " ") Then 'See if space exists
                    intSpacePos = InStr(1, subkey_name, " ") 'Get index of space
                    strMajor = Mid$(subkey_name, intSpacePos + 1, 2) 'Find Major version
                    strMinor = Mid$(subkey_name, intSpacePos + 4, 2) 'Find Minor version
                   
                    MsgBox subkey_name 'display full version
                    MsgBox strMajor 'display major version
                    MsgBox strMinor 'display minor version
            End If
    
        End If
        Loop
        ' Close the key.
        If RegCloseKey(hKey) <> ERROR_SUCCESS Then
            MsgBox "Error closing key."
        End If
    
    
    End Sub
    
    Private Sub Form_Load()
    Dim key_name As String
    
        key_name = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
        GetKeyInfo (key_name)
    End Sub
    I went further and added the capability to extract both Major and Minor versions as well.

    I am attaching the sample here for you, let me know if come right
    Attached Files Attached Files

  9. #9
    Join Date
    May 2013
    Posts
    5

    Re: get opera version

    Hi HanneSThEGreaT,

    Thanks for that, your code rocks, i indeed get the msgboxes with Opera version. So now i need to modify it now to get msgbox but to have it in a log. thanks for the help

  10. #10
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: get opera version

    Cool, I'm glad we're making progress

    OK, to have a log isn't too complicated. Add this Sub to your program :

    Code:
    Private Sub WriteLog(strEntry As String)
      
       Dim strLogFileName As String
       Dim strLogPath As String
       Dim lngLogSize As Long
       Dim fso
       Dim fFile
       
    On Error GoTo ErrHandler
    
       'Path = app path
       strLogPath = App.Path & "\" & App.EXEName
       strLogFileName = strLogPath & ".log" 'Give .log Extension
       
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set fFile = fso.OpenTextFile(strLogFileName, 8, True) 'Append onto existing file
       
       fFile.WriteLine Now() & vbTab & strEntry
       
    ErrHandler:
        Exit Sub
        
    End Sub
    And edit your existing GetKeyInfo Sub to include the call to the WriteLog sub instead of MsgBoxes :

    Code:
    '                MsgBox subkey_name 'display full version
    '                MsgBox strMajor 'display major version
    '                MsgBox strMinor 'display minor version
    
            WriteLog "Full Version : " & subkey_name
            WriteLog "Major version : " & strMajor
            WriteLog "Minor Version : " & strMinor

    I am attaching the edited project here as well

    I hope this helps and is what you're looking for.

    Hannes
    Attached Files Attached Files

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

Featured