|
|||||||
|
|
|
|||||
|
|
|||||||
VB Tips: Application and System
How to read program names associated with particular extensions from the Windows Registry? Try . . .
Calling DZLoadProgram
This example shows the use of DZLoadProgram to return the value for the Text
extension, .txt.
Dim wrkProgramName As String
Dim wrkProgramCall As String
'
' Get Program Name
DZLoadProgram "txt", wrkProgramName, wrkProgramCall
MsgBox wrkProgramName & " - " & wrkProgramCall
Note : A typical return for txt will return something
like txtfile and c:\windows\NOTEPAD.EXE %1, when the routine DZLoadProgram tests the
Windows Registry with txt.
This routine only works for 32-bit versions of Visual Basic.
DZLoadProgram
The routine, DZLoadProgram, reads the Windows Registry for the program to
open a particular extension.
Public Sub DZLoadProgram(ProExt as String, ProgramName as String, _
ProgramCall as String)
'
' This Routine actually gets the Program String associated
' with a particular extension.
Dim StrLen As Integer
Dim OutBuffer As String
Dim Work As String
Dim Work2 As String
Dim kk As Integer
Dim pos As Integer
Dim LocalFixedString As String * 200
'
' Get Program Name associated with a particular extension
On Error Resume Next
ProgramName = ""
ProgramCall = ""
If (Left$(ProExt, 1) = ".") Then
Work = ProExt
Else
Work = "." & ProExt
End If
OutBuffer = DZGetRegString(Work)
'
' Fully Resolve using Registration Database
If (OutBuffer <> "") Then
'
' Store Program Name
ProgramName = OutBuffer
Work2 = DZGetRegString(OutBuffer)
If (Work2 <> "") Then ProgramName = Work2
'
' Loop until the shell is found
Do
Work = OutBuffer
OutBuffer = DZGetRegString(Work & "\shell\open\command")
If (OutBuffer <> "") Then
ProgramCall = OutBuffer
Exit Sub
End If
OutBuffer = DZGetRegString(Work)
If (OutBuffer = "") Then Exit Sub
Loop
'
' Get from win.ini if not in Registration Database
Else
LocalFixedString = String(140, 32)
StrLen = GetProfileString("Extensions", ProExt, "", _
LocalFixedString, 128)
'
' Change Program Call to Registration Database Format
If (StrLen > 0) Then
Work = Trim$(LCase$(Left$(LocalFixedString, StrLen)))
pos = InStr(Work, "^." & LCase$(ProExt))
If (pos <= 0) Then
ProgramCall = Work
Else
ProgramCall = Left(Work, pos - 1) & "%1"
pos = pos + 5
If (pos <= Len(Work)) Then
ProgramCall = ProgramCall & Mid$(Work, pos)
End If
End If
End If
End If
End Sub
Note : The Windows API routine, GetProfileString, gets values from win.ini.
Declare Function GetProfileString Lib "kernel32" _
Alias "GetProfileStringA" _
(ByVal lpAppName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Long) As Long
As with the routine, DZGetRegString, this routine is very important and should be checked and understood.
Copyright (c) 1999 - 2001, robert han, all rigths are reserved.