Associating files with exe during run time  
Author Message
nevyn





PostPosted: Wed Nov 05 07:02:23 CST 2003 Top

Visual Basic >> Associating files with exe during run time

Hi

I have a requirement as follows

1) Find the path of excel.exe (it may be c:\Program
Files\Microsoft Office\office10 or some other folder)

2) associate files of type *.xls to app.path\a.exe

(if a.exe is not found - give message

3) at end of program associate *.xls back to excel.exe

Please let me how to do this in VB

thanks
rk

Visual Studio356  
 
 
Jan





PostPosted: Wed Nov 05 07:02:23 CST 2003 Top

Visual Basic >> Associating files with exe during run time
on Wed, 5 Nov 2003 03:27:52 -0800 bearing the following
fruit:

>Hi
>
>I have a requirement as follows
>
>1) Find the path of excel.exe (it may be c:\Program
>Files\Microsoft Office\office10 or some other folder)
>
>2) associate files of type *.xls to app.path\a.exe
>
>(if a.exe is not found - give message
>
>3) at end of program associate *.xls back to excel.exe
>
>Please let me how to do this in VB
>
>thanks
>rk

I'd be interested in knowing *why* you want to do this. It
may be that there is a simpler solution.

J

--
Lavatory: Volcano (Ray Hand)

[Abolish the TV Licence - http://www.tvlicensing.biz/]

 
 
Paul





PostPosted: Wed Nov 05 11:16:03 CST 2003 Top

Visual Basic >> Associating files with exe during run time

¤ Hi
¤
¤ I have a requirement as follows
¤
¤ 1) Find the path of excel.exe (it may be c:\Program
¤ Files\Microsoft Office\office10 or some other folder)
¤
¤ 2) associate files of type *.xls to app.path\a.exe
¤
¤ (if a.exe is not found - give message
¤
¤ 3) at end of program associate *.xls back to excel.exe
¤
¤ Please let me how to do this in VB

You can find the path to Excel using the following code:

Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (ByVal lpFile As String,
ByVal lpDirectory As String, ByVal lpResult As String) As Long

Function ExcelPath() As String

Dim sDummyFile As String
Dim sDir As String
Dim sFilePath As String * 255

sDummyFile = "e:\My Documents\book1.xls"

If FindExecutable(sDummyFile, sDir, sFilePath) > 32 Then
ExcelPath = TrimNull(sFilePath)
End If

End Function

Function TrimNull(item As String) As String

Dim pos As Integer

pos = InStr(item, Chr$(0))

If pos Then
TrimNull = Left$(item, pos - 1)
Else: TrimNull = item
End If

End Function

With respect to file associations, see the following:

http://www.mvps.org/vbnet/code/reg/association.htm



Microsoft MVP (Visual Basic)