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
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
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 :
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.
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.
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.
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
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
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
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.