Get the Application associated with the Shell Print Command for a File Type

106 19


For most of the file types on your system, when you right click a file in Windows Explorer, you will locate the "Print" command.

Executing the Print shell command, will result in the file being sent to the default printer. For some file types, like .TXT, a hosting application (Notepad, by default) will open the file first, for some the file would simply be printed (Word Docuemnt - .DOC). Some file types do not have an associated print command application.

File - Right Click - Print. Who will print?

If your want to programmatically print files from Delphi code, using the associated shell application, you need to first make sure that there is an application associated with the shell's print command for a given file type.
uses registry;// get the application (+command line usage) assiciated with // the Shell PRINT command for a given file GetShellPrintAssociatedCommand(const fileName: string): string; var   extension : string;   extDescriptor : string; begin   result := '';   extension := ExtractFileExt(fileName) ;  with TRegistry.Create do   try     RootKey := HKEY_CLASSES_ROOT;     if OpenKeyReadOnly(extension) then     begin       extDescriptor := ReadString('') ;       CloseKey;     end;    if extDescriptor <> '' then     begin       if OpenKeyReadOnly(extDescriptor + '\Shell\Print\Command') then       begin         result:= ReadString('') ;       end     end;   finally     Free;   end; end;
Delphi tips navigator:
» Reposition Inherited Control Back to Its Original Position - Revert To Inherited in Delphi IDE
« File Size - Get the Size of a File in Bytes using Delphi

Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.