Solved

Is Windows Media Player installed and if so what version

Posted on 2006-11-06
2
180 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 168
Delphi selector screen 2 92
Unique identifier on a terminal server (rdp) 4 75
Moving (cutting/pasting) controls in a TTabbedNotebook... 7 48
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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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