Solved

Is Windows Media Player installed and if so what version

Posted on 2006-11-06
2
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month7 days, 16 hours left to enroll

617 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