Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Is Windows Media Player installed and if so what version

Posted on 2006-11-06
2
Medium Priority
?
202 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 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

885 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