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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find User's Default Program of Choice 2

Status
Not open for further replies.

xBaseDude

MIS
Jan 31, 2002
357
US
Hi!

Is there anyway to find what the user has set as his main "Open With" program.

iow...is there anyway to find out if a user prefers "Mozilla", "Opera" or "IE" as their internet browser. Can I also easily find the "path" to that exe?

TIA - Wayne


sig_jugler.gif
...all this and tap dancing too!
 
xBaseDude,

This might be what you need.

Code:
?GetFileAssoc('MyHtml.HTM')
?GetFileAssoc('MyBitmap.BMP')

Function GetFileAssoc(tcFile)
Local lcExecFile
    If file(tcFile)  && file must exist
        Declare Long FindExecutable in Shell32 ;
            String cFile, String cDir, String @cExecFile

        lcExecFile = replicate(c0, 255)
        If (FindExecutable(tcFile, Null, @lcExecFile) > 32)
            lcExecFile = left(lcExecFile, at(chr(0), lcExecFile)-1)
        endif
        Clear Dlls FindExecutable

        If !file(lcExecFile)
            lcExecFile = .F.
        endif
    endif

    Return lcExecFile
EndFunc

Regards

-- AirCon --
 
Here's another way to do it reading the info from the registry. Cut-n-paste the code below into a prg and run it from within VFP.

Code:
MESSAGEBOX(FindExtAssoc("HTM"))
MESSAGEBOX(FindExtAssoc("BMP")) 

***********************
FUNCTION FindExtAssoc(tcExtension)
***********************
	SET ASSERTS ON && Just to make sure it is on, line can be removed if you have it on in your application
	ASSERT TYPE("tcExtension") = "C" MESSAGE "Developer Error: Parameter was not as expected."

	LOCAL oShell, lcErrorWas, lcReturn, llParamCheck
	tcExtension = "." + ALLTRIM(tcExtension)
	oShell  = CreateObject("wscript.shell")
	lcErrorWas = ON("ERROR") && Save previous error handling
	ON ERROR lcReturn = ""
	lcReturn = oShell.RegRead ("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" + tcExtension + "\OpenWithList\a")
	ON ERROR &lcErrorWas
	RETURN lcReturn
ENDFUNC


boyd.gif

craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Gentlemen;

Thank-You for taking the time to share your knowledge with me. I will check out your suggestions and see what works for me.

Regards - Wayne

Palmsun.gif
...Aloha!
 
The solution Craigs had came the closest to what I was trying to accomplish.

It did find my correct "open with" browser, but when I changed the variable ...

MESSAGEBOX(FindExtAssoc("HTM"))

to

MESSAGEBOX(FindExtAssoc("MP3"))

it did find a program to play the MP3, but it was not my primary "open with" program. I use "WinAmp" set as my default and it found "Sound Forge"

Any idea how to find the main [default] "open with" exe?

Regards - Wayne


Palmsun.gif
 
xBaseDude,

Is the function I posted doesn't work ?

-- AirCon --
 
AirCon;

Thank-You for your kind assistance.

"...the function I posted doesn't work ?"

When I executed your example under WinXP and VFP7.1, all that was returned was ".F."

Am I missing something?

Regards - Wayne
 
I made a small mistake in the code. Here is the change. Btw, the file to pass as parameter must exist and use a fullpath.
Code:
cFilename = fullpath('MyHtml.HTM')
?GetFileAssoc(cFilename)

cFilename = fullpath('MyBitmap.BMP')
?GetFileAssoc(cFilename)

Function GetFileAssoc(tcFile)
Local lcExecFile
   If file(tcFile)  && file must exist
      Declare Long FindExecutable in Shell32 ;
         String cFile, String cDir, String @cExecFile

      lcExecFile = replicate([b]chr(0)[/b], 255)
      If (FindExecutable(tcFile, Null, @lcExecFile) > 32)
         lcExecFile = left(lcExecFile, at(chr(0), lcExecFile)-1)
      endif
      Clear Dlls FindExecutable

      If !file(lcExecFile)
         lcExecFile = .F.
      endif
   endif

   Return lcExecFile
EndFunc

Try again :)

-- AirCon --
 
-- AirCon --

That one worked!

I was kinda disappointed that "a" file with the file ext had to actually exist. Wish it could have just taken a variable. Knowing where to "look" to find a specific file type is a pita.

Thanx for sharing your knowledge with me.

Regards - Wayne

Palmsun.gif
Aloha!
 
Wayne,

I got your point and you are right. I changed it so you only have to pass the extension only
Code:
? GetFileAssoc('HTM')
? GetFileAssoc('JPG')

Function GetFileAssoc(tcExt)
Local lcExecFile, lcTempFile
   Declare Long FindExecutable in Shell32 ;
      String cFile, String cDir, String @cExecFile

   lcExecFile = replicate(chr(0), 255)
   lcTempFile = tcExt + sys(2015) + '.' + tcExt
   = StrToFile(tcExt, lcTempFile)
   If (FindExecutable(lcTempFile, Null, @lcExecFile) > 32)
      lcExecFile = left(lcExecFile, at(chr(0), lcExecFile)-1)
   endif
   Erase (lcTempFile)
   Clear Dlls FindExecutable

   If !file(lcExecFile)
      lcExecFile = .F.
   endif

   Return lcExecFile
EndFunc

Hope that helps

-- AirCon --
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top