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
Dzomlija

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
Dzomlija

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
Thread Forum
WMP 64 bit - scrambled file associations - no media will play
I recently reinstalled Windows 7 on my PC, and was getting everything set up again, when I ran into a bug that I can't believe is still present in Windows 7 after two years of it being a supposedly known issue. This bug pertains to WMP 12 64 bit. I fell victim to this bug back in 2010, but...
General Discussion
How to Backup Windows 7 Default (Customized) File Associations
Does anyone know how you can backup your personal customizations to the Default File Locations (e.g., my *.txt isn't assocated with Notepad, but Notepad2). Is it in the registry somewhere?
Backup and Restore
file associations
I am experiencing a change in the way my PC works. If I do Start>Computer and then click on, say, my C: drive (but it happens for all drives) I get that darned message "The file does not have a program associated with it for performing this action....etc". If I right click and choose "open", then...
General Discussion
Prevent Windows Media Center from autoplay a DVD
Is there an easy way that I can configure my computer, so that each time I put a movie DVD into my drive that media center won't automatically fire up and try to plaback the movie. I often rip movies from Netflix onto DVD+RW's and watch them later. However, when I put in the DVD+RW to erase...
Media Center
Two Windows media player autoplay handlers
Whenever I insert a DVD, the autoplay menu will pop up and there will be a bunch of handlers but for some reason there is always two windows media player handlers in the auto play menu. This also happen in the autoplay menu found in control panel: when I open the list of programs under "DVD movie",...
General Discussion
File associations WMP
Hi folks, first post here because I did a search for answer, but to no avail. Somehow or another when I setup WMP I wanted iTunes and quicktime to handle certain filetypes, and WMP to handle "windows only" file types, Not to mention Pro Tools to handle midi etc. Anyway, I can't seem to change...
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 14:32.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App