#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2007
    Posts
    5
    Rep Power
    0

    Unhappy File Association and the registry


    I come to you in desperation as I've been struggling with this problem all weekend. So obsessed with it have I become that I even dreamt about it last night.

    My problem is this. For the past couple of months I have been creating my own media player in Delphi and I must admit that it's really coming along very nicely.

    This weekend I finally got around to doing some of the options in 'preferences' and one of these was the file associations. The idea, as you expect, is that the user can select various extensions, such as .avi, .mpg, .mp3 etc.. and assign them to my programme so that the next time they double-click on one of these files it's my media player that opens and plays them and not, say, windows media player.

    So far so good...

    Now it seems no matter what I do, how I change the registry using examples found on various sites, whether I run the programme as an admin or not it doesn't make the slightest difference. I simply cannot change any file association to my media player.

    Further imagine my utter frustration when I download media players such as Zoom Player or the DIVX Player and go into their options dialog and find that within a couple of clicks I can assign extensions to them with no problem whatsoever. What is it that they are doing that my media player isn't?

    So, to cut a long story short I suppose the real question is this. What registry entries do I need to change (without having to run my app in admin mode as I didn't with Zoom Player etc.) to associate certain filetypes such as .avi with my media player that actually works under Windows 7?

    Can I confine myself entirely to HKEY_CURRENT_USER for example?

    Many thanks in advance
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2007
    Posts
    5
    Rep Power
    0

    Solved


    procedure TForm1.RegisterFileType(ExtName:String);
    var
    a: byte;

    begin
    a:=0;

    with TRegistry.Create do
    try
    RootKey := HKEY_CLASSES_ROOT;

    DeleteKey('\.avi\');

    if OpenKey('\.avi\', True) then begin
    WriteString('','avifile');
    WriteString('PerceivedType', 'video');
    WriteString('Content Type', 'video/avi');
    end;

    OpenKey('\.avi\OpenWithList\ehshell.exe\', True);

    if OpenKey('\.avi\OpenWithProgIds\', True) then
    WriteBinaryData('avifile', a, 1);

    if OpenKey('\avifile\shell\open\command\', True) then
    WriteString('', '"'+ParamStr(0)+'" "%1"');

    RootKey := HKEY_CURRENT_USER;

    DeleteKey('\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.av​i\');

    if OpenKey('\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.avi\OpenW​ithProgids\', True) then
    WriteBinaryData('avifile', a, 1);

    finally
    Free;
    end;

    SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
    end;

IMN logo majestic logo threadwatch logo seochat tools logo