Solved

Is Windows Media Player installed and if so what version

Posted on 2006-11-06
2
173 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
ID: 17884437
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
ID: 17888457
Excellent response. Thank you very much.

Jim Voelker
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

770 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