New
#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.
- How do enable Autoplay for External Hard Disks and Flash Drives on Windows 7?
- 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:
Autoplay
Enabling autoplay is actually very easy. All it takes is a file named autoplay.inf in the root of the disk:
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.Code:[autorun] open=map.exe action=Prometheus Movie Autoplay Manager
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.
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:ShellExecute(Application.Handle, nil, pChar(AFilename), nil, nil, SW_SHOW);
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?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;
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?