Solved

Is Windows Media Player installed and if so what version

Posted on 2006-11-06
2
169 Views
Last Modified: 2010-04-05
How can I determine from a Delphi program whether Windows Media Player is installed and also determine the version installed?
0
Comment
Question by:JVoelker
2 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 500 total points
Comment Utility
Source first, example follows.

const
  WMP_ROOTKEY       =  HKEY_LOCAL_MACHINE;
  WMP_SUBKEY        =  'SOFTWARE\Microsoft\MediaPlayer';
  WMP_INSTALL       =  'Installation Directory';
  WMP_PROGRAM       =  'wmplayer.exe';

function IsMediaPlayerInstalled(var VersionString: String): Boolean;
var  lpszPath:      Array [0..MAX_PATH] of Char;
     lpBuffer:      Pointer;
     lpFixed:       PVSFixedFileInfo;
     lpFind:        TWIN32FindData;
     hFind:         THandle;
     hkeyWMP:       HKEY;
     dwHandle:      DWORD;
     dwSize:        DWORD;
begin

  // Check registry first to get the path
  if (RegOpenKeyEx(WMP_ROOTKEY, WMP_SUBKEY, 0, KEY_READ, hkeyWMP) = ERROR_SUCCESS) then
  begin
     // Resource protection
     try
        // Set buffer size
        dwSize:=SizeOf(lpszPath);
        // Read the installation directory
        if (RegQueryValueEx(hkeyWMP, WMP_INSTALL, nil, nil, @lpszPath, @dwSize) = ERROR_SUCCESS) then
        begin
           // Concat the program file to the the path
           StrPLCopy(@lpszPath, IncludeTrailingBackslash(lpszPath) + WMP_PROGRAM, Pred(MAX_PATH));
           // Query path existence
           hFind:=FindFirstFile(lpszPath, lpFind);
           // Check handle
           if (hFind = INVALID_HANDLE_VALUE) then
              // Program does not exist
              result:=False
           else
           begin
              // Resource protection
              try
                 // Success, found the program
                 result:=True;
                 // Now get the file version info
                 dwSize:=GetFileVersionInfoSize(@lpszPath, dwHandle);
                 // Check size
                 if (dwSize > 0) then
                 begin
                    // Allocate memory
                    lpBuffer:=AllocMem(dwSize);
                    // Resource protection
                    try
                       // Get the verison info
                       if GetFileVersionInfo(@lpszPath, 0, dwSize, lpBuffer) and VerQueryValue(lpBuffer, '\', Pointer(lpFixed), dwSize) then
                       begin
                          // Get the major minor release and build
                          VersionString:=IntToStr(HiWord(lpFixed^.dwFileVersionMS)) + '.' +
                                         IntToStr(LoWord(lpFixed^.dwFileVersionMS)) + '.' +
                                         IntToStr(HiWord(lpFixed^.dwFileVersionLS)) + '.' +
                                         IntToStr(LoWord(lpFixed^.dwFileVersionLS));
                       end
                       else
                          // Clear passed buffer
                          SetLength(VersionString, 0);
                    finally
                       // Free memory
                       FreeMem(lpBuffer);
                    end;
                 end
                 else
                    // Clear passed buffer
                    SetLength(VersionString, 0);
              finally
                 // Close the handle
                 Windows.FindClose(hFind);
              end;
           end;
        end
        else
           // Failed to get the installation path
           result:=False;
     finally
        // Close the registry key
        RegCloseKey(hkeyWMP);
     end;
  end
  else
     // Registry key does not exist / can't be opened
     result:=False;

end;


// Example usage
var  szVersion:     String;
begin

  if IsMediaPlayerInstalled(szVersion) then
     ShowMessage(szVersion);

end;

----

Regards,
Russell
0
 

Author Comment

by:JVoelker
Comment Utility
Excellent response. Thank you very much.

Jim Voelker
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now