views:

68

answers:

3

Anybody have any advice on how to programmatically detect if Windows Media Player is installed?

I know about the registry setting 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.

+5  A: 

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.

Vantomex
This is awesome, but is it documented anywhere that this value is actually set to 0 on uninstall?
John MacIntyre
I've ever tested uninstalling WMP 9 in My VM, and it was indeed `IsInstalled` set to `0`. Since the year of the MSDN documentation is 2010, I'm sure this behaves the same at least until WMP 12.
Vantomex
+2  A: 

(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.

Duncan Smart
+1  A: 

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.

Brazzle
I like that idea of checking the installed app via the path in the registry. +1
John MacIntyre