Programmatically detect if Windows Media Player is installed
Anybody have any advice on how to programmatically detect if Windows Media Player is installed?
I know about the registry settin开发者_C百科g look up, but don't trust it since it's more than a little misleading (uninstalled may not remove it). And I've considered just launching a video, but an error could be caused by something other than Media Player not being installed, so it's not conclusive either.
Ideally, I'd prefer a solution which could be used from both my C++ application AND my NSIS installer. But my the C++ app is the most important, I'm willing to live with the registry hack in the installer.
Look at the IsInstalled
value under key HKLM\Software\Microsoft\Active Setup\Installed Components\{22d6f312-b0f6-11d0-94ab-0080c74c7e95}
. It is 1
if installed, 0
otherwise.
See Detecting Windows Media Player from an Application.
(You don't say whether you're checking for an embeddable (i.e. OCX) player to embed in your app or the EXE to launch extenally from your app.)
How about checking the HRESULT on CoCreateInstance against CLSID {22d6f312-b0f6-11d0-94ab-0080c74c7e95} / ProgID "MediaPlayer.MediaPlayer.1" in your app? (CLSIDs from http://technet.microsoft.com/en-us/library/bb676121.aspx)
In your installer just check for HKEY_CLASSES_ROOT\CLSID{22D6F312-B0F6-11D0-94AB-0080C74C7E95}, and perhaps also that the path at the InprocServer32 subkey exists.
If the uninstall fails to remove both the EXE and the registry entry then I highly doubt it uninstalled anything...
So, I would suggest you check the registry under HKLM\Software\Microsoft\MediaPlayer\
and if it exists, grab the value of the Installation Directory
or Installation DirectoryLFN
(default is %ProgramFiles%\Windows Media Player
) and check that wmplayer.exe
exists within that directory. If it does, then you will know that WMP is installed.
精彩评论