Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect Flash Plugin

Status
Not open for further replies.

alsaffar

Programmer
Oct 25, 2001
165
KW
Hi there,

I embedded flash (.swf) files in my VB application programmed in VB6. Its working fine, but in PC where there micromedia shockwave is not defined it will not work :( if its a web page that contain flash and the PC is conected to the internet, it will download (.cab) file from micromedia.com

Now I have the (.cab) file, how can I make my application check if the .cab file is not installed on the running PC it will execute the .cab file I pack with my application?

Please help guys ;)
 
You could look at the system registry for shockwave. Try this:

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 RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
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
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 RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpname As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As FILETIME) As Long

Public Const SYNCHRONIZE = &H100000
Public Const STANDARD_RIGHTS_READ = &H20000
Public Const STANDARD_RIGHTS_WRITE = &H20000
Public Const STANDARD_RIGHTS_EXECUTE = &H20000
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
Public Const STANDARD_RIGHTS_ALL = &H1F0000
Public Const KEY_QUERY_VALUE = &H1
Public Const KEY_SET_VALUE = &H2
Public Const KEY_CREATE_SUB_KEY = &H4
Public Const KEY_ENUMERATE_SUB_KEYS = &H8
Public Const KEY_NOTIFY = &H10
Public Const KEY_CREATE_LINK = &H20
Public Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Public Const REG_DWORD = 4
Public Const REG_BINARY = 3
Public Const REG_SZ = 1
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 ERROR_SUCCESS = 0&

Public Function FindShockwave() As Boolean
Dim stemp, spath As String

spath = "ShockwaveFlash.ShockwaveFlash.1"
stemp = RegGetEnumValue(HKEY_CLASSES_ROOT, spath)
spath = RegGetStringValue(HKEY_CLASSES_ROOT, spath, "")

If spath = "Shockwave Flash Object" Then
FindShockwave = True
Else
FindShockwave = False
End If
End Function

Function RegGetEnumValue(hKey As Long, spath As String)
Dim lKeyHandle As Long, lResult As Long, lCurIdx As Long
Dim sValue As String, sResult As String
Dim lValueLen As Long, lData As Long, lDataLen As Long

lResult = RegOpenKeyEx(hKey, spath, 0&, KEY_READ, lKeyHandle)
If Not lResult = ERROR_SUCCESS Then Exit Function
Do
lValueLen = 2000
sValue = String(lValueLen, 0)
lDataLen = 2000
lResult = RegEnumValue(lKeyHandle, lCurIdx, ByVal sValue, lValueLen, 0&, REG_DWORD, ByVal lData, lDataLen)
lCurIdx = lCurIdx + 1
If lResult = ERROR_SUCCESS Then
sResult = Left(sValue, lValueLen) & "," & sResult
End If
Loop While lResult = ERROR_SUCCESS
Call RegCloseKey(lKeyHandle)
If Not Len(sResult) = 0 Then sResult = Left(sResult, Len(sResult) - 1)
RegGetEnumValue = sResult
End Function

Public Function RegGetStringValue(hKey As Long, spath As String, sValue As String)
Dim lKeyHand As Long
Dim lValueType As Long
Dim lResult As Long
Dim sBuff As String
Dim lDataBufSize As Long
Dim iZeroPos As Integer

RegOpenKey hKey, spath, lKeyHand
lResult = RegQueryValueEx(lKeyHand, sValue, 0&, lValueType, ByVal 0&, lDataBufSize)
If lValueType = REG_SZ Then
sBuff = String$(lDataBufSize, " ")
lResult = RegQueryValueEx(lKeyHand, sValue, 0&, 0&, ByVal sBuff, lDataBufSize)
If lResult = ERROR_SUCCESS Then
iZeroPos = InStr(sBuff, Chr$(0))
If Not iZeroPos = 0 Then
RegGetStringValue = Left$(sBuff, iZeroPos - 1)
Else
RegGetStringValue = sBuff
End If
End If
End If
RegCloseKey lKeyHand
End Function

Sub Start()

If Not FindShockwave Then MsgBox ("Shockwave not found!")

End Sub

-Mike
 
Mike ur script is working just GREATE ;)

The question now, I have the SWFLASH.CAB that contains:

SWFlash.ocx and SWFlash.ini

Where do I have to copy them if I noticed that Shockwave is not installed on the PC?

I found them in my PC under C:\WINDOWS\ServicePackFiles\i386 (Note that Im using WinXP Pro)
 
Those 2 files are in CAB file, if I execute the CAB file, will they distribute correctly? and how can I execute the CAB file via VB Code?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top