Windows 7 Autoplay and Media File Associations


  1. Posts : 1,261
    Windows 7 Professional 32-bit SP1
       #1

    Windows 7 Autoplay and Media File Associations


    I'm asking the following two questions here in General Discussion, becase Sevenforums does not have a Developers Forum.
    1. How do enable Autoplay for External Hard Disks and Flash Drives on Windows 7?
    2. How to locate the executable association that is used with a particular media file association?


    In-case you are wondering why I need to know this information, it's because I'm working on an autoplay application that mimics the behavior of the Mede8er Video Wall. The idea being that if I've made backups to an external USB Hard Disk of all my media files, and I connect the drive to my PC, the autoplay function of Windows will open the application, which is a kind of database of the movies stored on the drive. A picture is worth a thousand words, so the screenshot below will describe it better:
    Windows 7 Autoplay and Media File Associations-map_screenshot.jpg

    Autoplay

    Enabling autoplay is actually very easy. All it takes is a file named autoplay.inf in the root of the disk:
    Code:
    [autorun] 
    open=map.exe 
    action=Prometheus Movie Autoplay Manager
    When used on CD or DVD disks, it works on all versions of Windows XP, Vista and Windows 7. However, if used on other media, such as a USB Flash Drive or USB Hard Disk, Windows Vista and Windows 7 completely ignore the autoplay open command. Microsoft was kind enough to supply a patch Update to the AutoPlay functionality in Windows.

    Because the aforementioned update is available only for Windows XP, Windows Vista and Windows Server, I've coded my application in such a manner that when it is manually launched from an external hard disk (by double-clicking the map.exe file), it will automatically scan for media files in a hard-coded folder named "Movies".

    I would prefer to have the icon for the application to appear in the Windows autoplay dialog, so that I can specify command-line options in the autoplay.inf file.

    So my question is this, because Windows 7 AutoPlay only recognises the Icon and Label entries in autorun.inf : How do I enable autoplay for external USB Hard Disks on Windows 7?



    File Associations

    I prefer to use Windows Media Player for my movies, music and DVDs, but this is not a preference that is shared by other users, so my application must be able to automatically and transparently determine which program must be used to launch movie files.

    For example, if I double-click a icon in my program, it will determine that the file "O:\Movies\Sci-Fi\Star Trek 11\Star Trek 11.avi" needs to be played. If a single file must be opened, I can easily use ShellExecute, because Windows itself will take care of determining the appropriately associated program with which to open the file.
    Code:
    ShellExecute(Application.Handle, nil, pChar(AFilename), nil, nil, SW_SHOW);
    But the above does not work if more than one video file needs to be opened. For that, ShellExecute needs to know the full path name of the program to execute, and the appropriate parameters that needs to be passed to it. The following is a code extract from my application:

    Code:
    procedure TFormMainMovies.PlayMovies(AFileList:TStringList); 
    var 
      BufferSize : DWORD; 
      ExpandedCmd : string; 
      MediaPlayer : string; 
      ExeReturn:HINST; 
      VideoFiles:TStringList; 
      Parse : Integer; 
    begin 
      {} 
      MediaPlayer := '%ProgramFiles(x86)%\Windows Media Player\wmplayer.exe'; 
      ExpandedCmd := ''; 
      BufferSize := ExpandEnvironmentStrings(pChar(MediaPlayer), pChar(ExpandedCmd), 0); 
      if BufferSize > 0 then 
        begin 
          VideoFiles := TStringList.Create; 
          try 
            {} 
            ExpandedCmd := StringOfChar(#0, BufferSize); 
            BufferSize := ExpandEnvironmentStrings(pChar(MediaPlayer), pChar(ExpandedCmd), Length(ExpandedCmd)); 
            if BufferSize <= 0 then 
              begin 
                {could not expand media player environment string} 
              end 
            else 
                begin 
                  {When passing multiple files to wmplayer, a CRLF seperated list must be passed to ShellExecute} 
                  VideoFiles.Assign(AFileList); 
                  for Parse := 0 to VideoFiles.Count - 1 do 
                    VideoFiles.Strings[Parse] := #34 + Trim(VideoFiles.Strings[Parse]) + #34; 
     
                  {} 
                  ExeReturn := ShellExecute(Application.Handle, nil, pchar(ExpandedCmd), pChar('/fullscreen '+VideoFiles.Text), nil, SW_SHOW); 
                  if not (ExeReturn > 32) then 
                    begin 
                      {ShellExecute returned an error} 
                    end; 
                end; 
          finally 
            FreeAndNil(VideoFiles); 
          end; 
        end; 
    end;
    The question I'm asking is this: Given a particular file type (AVI, MPG, DIVX), how do I determine the fully qualified path to the exe that opens the file? Is there a (simple) API call that I can use to do this, or do I need to read the registry manually?

    Also, my program currently only searches for AVI, MPG, MPEG and DIVX file types. In relation to videos, what other file extensions should I be looking for?
      My Computer


  2. Posts : 1,261
    Windows 7 Professional 32-bit SP1
    Thread Starter
       #2

    I'm guessing then that there are no developers that can assist with this project?
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 14:47.
Find Us