Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: FoxPro FAQ

Usefull Functions & Procedures

Associate your VFP app with a specific file extension by craigsboyd
Posted: 6 Jul 03

Slighthaze = NULL
Want MyExecutable.exe to automatically start when the user clicks on a file with .AAA as the extension?  It's the same thing that happens when all those graphics programs on your PC are fighting over which gets to open the .JPG extension files when you double-click on a JPG image file.  With the code below your new VFP Graphics application will be ready to fight over those JPG files too. (IMPORTANT: Caution while playing with this code, you can end up with all kinds of invalid associations on your PC - such as a non-existant MyExecutable.exe program being associated with files that have .aaa extensions)

DO associatefile  WITH ".aaa", "MyProgramFile", "C:\Program Files\MyFolder\MyExecutable.exe"

PROCEDURE associatefile (sExtension, sFileDescription, sExecutable)
    LOCAL sErrorHandler
    sErrorHandler = ON("error")
    ON ERROR &&Necessary since the regdelete lines will error out if it doesn't exist
    oShell  = CreateObject("wscript.shell")
    oShell.Regwrite ("HKCR\" + sExtension + "\", sFileDescription)
    oShell.Regwrite ("HKCR\" + sFileDescription + "\", "MY PROJECT")
    oShell.Regwrite ("HKCR\" + sFileDescription + "\DefaultIcon\", sExecutable)
    oShell.Regwrite ("HKCR\" + sFileDescription + "\shell\open\command\", sExecutable + " %1")
    oShell.Regdelete ("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" + sExtension + "\Application")
    oShell.Regwrite ("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" + sExtension + "\Application", sExecutable)
    oShell.Regdelete ("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" + sExtension + "\OpenWithList\")
    oShell.Regwrite ("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" + sExtension + "\OpenWithList\a", sExecutable)
    ON ERROR &sErrorHandler

Back to Microsoft: FoxPro FAQ Index
Back to Microsoft: FoxPro Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close