Solved

quitely printing a file

Posted on 1998-07-22
14
254 Views
Last Modified: 2013-11-20
How can I send a file to the default printer without opening its application or the printer dialog? The file type is known to the shell (ex. *.doc)

Details of the question:
1.Do I need to have this file saved in a special format?
(When I checked the option SaveToFile in my printer dialog, I got the file in *.prn format. )
2. Does *.prn format depend on the printer selected when the file is printed_to_file?
3. How to make my application send this file (or original file *.doc for example) to the printer
4. How to make my application prevent opening the printer dialog but make sure that I am using the default printer.
5. How to get the result of the printing job (success, fail,..etc.)
0
Comment
Question by:khaledo
  • 6
  • 5
  • 3
14 Comments
 
LVL 2

Expert Comment

by:duneram
ID: 1319642
If you are running on 95/98 or NT you can drag the file onto the top of the printer icon.  That will auto print the file without starting any applications.

If you wish to do it from within a program, you can always resort to the simple method (if its a text file) of

1)   build a command string of the form

     "notepad /p myfile.txt"

(if you have to build the text file yourself, you
   a. create it
   b. close it. )
2) run WinExec("notepad /p myfile.txt", SW_HIDE);

That willl spawn the notepad program, tell it to automatically print to the default printer, and 3 hide the window.

perhaps this will provide a quick method?

0
 

Author Comment

by:khaledo
ID: 1319643
Thanks, but this will not work unless the file original application accept a command line parameter. Not all applications accept /p parameter. plus it includes opening the file's original program which I want to avoid.

Is there a general solution or a way for me to send a file to the default printer from my program without needing its original application ?
0
 
LVL 2

Expert Comment

by:duneram
ID: 1319644
Notepad.exe does accept a /p parameter and it ships with windows.  Its the default text editor for text file.    using the SW_HIDE, hides the application as it runs and prints the file.  After it is done, the application automatically closes.  Its  a back door.

If you just want to spool a file to the printer without this quick and easy back door, you need to take a look at microsoft's article Q111010  or Q119113   they present api methods to do this without routing thru the printer....

To get there, go to http://support.microsoft.com/support/c.asp?FR=0 and enter Q111010 as the keyword to search on (choose all products). and then press find.
0
 

Author Comment

by:khaledo
ID: 1319645
microsoft's articles Q111010  and Q119113 provide solutions for local printers only.

Is it possible to just make my application send *.prn to the default printer (which can be network printer)? If yes, then I need some answers to my original question. If no, then I need another back door if possible.
 
Thnaks
0
 
LVL 2

Expert Comment

by:duneram
ID: 1319646
You can use the ShellExecute API to accomplish this task.

there is a 'print.exe' that ships with windows.  and it will route it to the default printer automatically.

If you did a ShellExecute(hwnd, "print", "filename.prn", "c:\", SW_HIDE);

That should do the trick
0
 

Author Comment

by:khaledo
ID: 1319647
Cannot find any print.exe on my HDD nor on my Window CD
Does it come with any Window's version?
My Window is 4.00.950 C
0
 
LVL 2

Expert Comment

by:duneram
ID: 1319648
I am running nt4 and it's there.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 23

Expert Comment

by:chensu
ID: 1319649
khaledo,

Have you tried what duneram suggested? I think the following should work.

ShellExecute(hwnd, _T("print"), _T("readme.txt"), NULL, NULL, SW_HIDE);

0
 
LVL 23

Expert Comment

by:chensu
ID: 1319650
Windows 95 does not have a print.exe. The ShellExecute does not need it.
0
 
LVL 2

Expert Comment

by:duneram
ID: 1319651
I just tried it on Win98 and it worked fine.  Earlier I was on NT 4 and it also worked fine.
0
 

Author Comment

by:khaledo
ID: 1319652
It is working.

ShellExecute(hwnd, _T("print"), _T("readme.txt"), NULL, NULL, SW_HIDE);

Thanks for duneram and chensu.


0
 
LVL 23

Expert Comment

by:chensu
ID: 1319653
duneram,

Post it as an answer so that khaledo can grade it.
0
 
LVL 2

Accepted Solution

by:
duneram earned 100 total points
ID: 1319654

You can use the ShellExecute API to accomplish this task.

     there is a 'print.exe' that ships with windows.  and it will route it to the default printer
     automatically.

     If you did a ShellExecute(hwnd, "print", "filename.txt", "c:\", SW_HIDE);

     That should do the trick
0
 

Author Comment

by:khaledo
ID: 1319655
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now