I have a situation where I need to be assured there's 'something' installed on a client machine that can display PDF's ..I dont care what that something is, ie, Acrobat, Foxit ... this technique may work, but is tied to an assumption that nothing else has 'highjacked' the extension '.pdf' in my case - in your case the extension would be iirc '.vlc'
public enum AssociationStr
{
Command = 1,
Executable,
FriendlyDocName,
FriendlyAppname,
NoOpen
}
and
[Flags]
public enum AssociationFlags
{
Init_NoRemapCLSID = 0x01,
Init_ByExeName = 0x02,
Init_DefaultToStar = 0x04,
Init_DefaultToFolder = 0x08,
NoUserSettings = 0x10,
NoTruncate = 0x20,
Verify = 0x40,
RemapRunDll = 0x80,
NoFixUps = 0x100,
IgnoreBaseClass = 0x200
}
then with
[DllImport("Shlwapi.dll". CharSet = CharSet.Auto, SetLastError = true)]
static extern uint AssocQueryString(AssociationFlags flags, AssociationStr str, string pszAssoc, string pszExtra, [Out] StringBuilder sOut, [In][Out] ref uint nOut);
you can do :-
public static string GetAssociatedExecutable(string docType)
{
string tmpAssocExe = FileInfoByExtension(AssociationStr.Executable, docType;
return tmpAsocExe;
}
public static string FileInfoByExtension(AssociationStr assocStr, string docType)
{
uint pcchOut = 0;
if (AssocQueryString(AssociationFlags.Verify, assocStr, docType, null, null, ref pcchOut) != 1)
return null;
StringBuilder pszOut = new StringBuilder((int)pcchOut);
if (AssocQueryString(AssociationFlags.Verify, assocStr, docType, null, pszOut, ref pcchOut) != 0)
return null;
return pszOut.ToString();
}
I've manually re-typed this from my dev machine thats off the network for the moment (Im typing on My Mac), so if there's any errors, do a Google for pinvoke AssocQueryString and you may get the info - I think it originally came from StackOverflow
oh, if its not obvious
string whatRunsVLC = GetAssociatedExecutable(".vlc");
(I think I split 'Executable' out into its own function because I also have a variant of it to get the DDEApplication)
[edit]
needs
using System.Runtime.InteropServices;
where you put 'the good bits' of this [/edit]