1. Home
  2. Computing & Technology
  3. Delphi Programming

Get the Application associated with the Shell Print Command for a File Type
What application will Print a file from the Shell's Print Command?

By , About.com Guide

Get the Application associated with the Shell Print Command for a File from Delphi

Get the Application associated with the Shell Print Command for a File from Delphi

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

More Delphi Programming Quick Tips
Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. Delphi 2008 Tips
  7. Get the Application associated with the Shell Print Command for a File Type from Delphi

©2009 About.com, a part of The New York Times Company.

All rights reserved.