none
How to check if a software is associated for a given file's ShellExe print command RRS feed

  • Question

  • Hi all,

    I want to write a program/method in C# that given a file, checks if there is a software associated for it for the shellexe print verb. Only if it is associated, retrieving the exe associated is secondary.

    Basically, if when the user right-clicks on the file in windows explorer and the context menu has the native 'print' option on it, I want my method to return true. I have already tried traversing the Registry structure and checking for the <key>/shell/print/command entry's existence.

    However, I found out that it is not always correct. On my testing machine, I right-click on a pdf, it shows that the print option is available, but when traversing the registry, there is no program associated with 'print', only 'open'. Same with jpg files.

    So I guess the base question is, how does Windows Explorer check if there is a software associated for a file's print command? And how can I use it in my C# code?

    Any help is most welcome!

    Cheers,

    Thimila

    P.S.: not sure if I am posting to the right forum. I think this is more related to Windows dev, I may be wrong. apologies in advance!

    Wednesday, July 3, 2013 10:32 AM

Answers

  • Hi Sheng,

    Thanks for the tip. My base requirement does not require the program command line. I just need to have a bool value that would indicate if the file is associated with any program for the print command. If TRUE, I am going to just call Process.Start() with "Print" as the StartInfo.Verb.

    I found the following api method:

    [DllImport("Shlwapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
    private static extern uint AssocQueryString(AssocF flags, AssocStr str, string pszAssoc, string pszExtra, [Out] StringBuilder pszOut, [In][Out] ref uint pcchOut);
    

    will this return me the data that I require correctly?
    Thanks!

    Cheers,
    Thimila
    Monday, July 8, 2013 6:11 AM
  • I assume it would work most of the time as most print verbs are static . Shell extensions can add verbs at run time and the only way to check their addition is to create the extensions and run though the menu-creation process.

    Suggested reading

    Choosing a Static or Dynamic Shortcut Menu Method



    Visual C++ MVP


    Monday, July 8, 2013 2:44 PM
    Moderator

All replies

  • What if the file is associated to a windows store application? You won't get the command line (store apps can't be launched from the command line), only the app id.


    Visual C++ MVP

    Saturday, July 6, 2013 6:54 PM
    Moderator
  • Hi Sheng,

    Thanks for the tip. My base requirement does not require the program command line. I just need to have a bool value that would indicate if the file is associated with any program for the print command. If TRUE, I am going to just call Process.Start() with "Print" as the StartInfo.Verb.

    I found the following api method:

    [DllImport("Shlwapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
    private static extern uint AssocQueryString(AssocF flags, AssocStr str, string pszAssoc, string pszExtra, [Out] StringBuilder pszOut, [In][Out] ref uint pcchOut);
    

    will this return me the data that I require correctly?
    Thanks!

    Cheers,
    Thimila
    Monday, July 8, 2013 6:11 AM
  • I assume it would work most of the time as most print verbs are static . Shell extensions can add verbs at run time and the only way to check their addition is to create the extensions and run though the menu-creation process.

    Suggested reading

    Choosing a Static or Dynamic Shortcut Menu Method



    Visual C++ MVP


    Monday, July 8, 2013 2:44 PM
    Moderator
  • Thanks Sheng!
    Monday, July 8, 2013 11:50 PM