Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Windows 7 Autoplay and Media File Associations


15 May 2011   #1

Windows 7 Ultimate x64
 
 
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 System SpecsSystem Spec
.

17 May 2011   #2

Windows 7 Ultimate x64
 
 

I'm guessing then that there are no developers that can assist with this project?
My System SpecsSystem Spec
Reply

 Windows 7 Autoplay and Media File Associations




Thread Tools



Similar help and support threads for2: Windows 7 Autoplay and Media File Associations
Thread Forum
WMP 64 bit - scrambled file associations - no media will play General Discussion
How to Backup Windows 7 Default (Customized) File Associations Backup and Restore
Solved File associations General Discussion
Prevent Windows Media Center from autoplay a DVD Media Center
File Associations Customization
Two Windows media player autoplay handlers General Discussion
File associations WMP Music, Pictures & Video

Our Sites

Site Links

About Us

Find 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 03:18 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33