Discussion:
IE Print Automation - Can't suppress print dialog
(too old to reply)
RLubanovic
2007-08-11 18:10:01 UTC
Permalink
Hi,

I have been trying to solve a batch printing issue for a few weeks. I
have tried numerous strategies and have posted a few questions. I have not
received any answers to this point. I will explain my latest strategy:

This is a VB.Net 2.0 app, and it uses C# for the printing object.

There is a difference between printing one invoice or a batch.

When I print one invoice, I can use the "open" verb and allow IE to
launch. This is nice because it allows the user to print preview, select the
printer and print. Then they close IE and return to the app.

When I want to print a batch, I can select the printer ahead of time, then
call IE in a loop with the "print" verb and expect to print them all using
the default printer.

The issue is that IE wants to prompt me for the printer every time. This
is not good.

I am attempting to redirect standard in to recieve the default printer
from a stream. In order to do this, I had to change the code to the
following snippett:

Process proc = new Process();

if (fPromptForPrinter)
{
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.Verb = "open";
proc.StartInfo.FileName = strFileName;
}
else
{
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
proc.StartInfo.Verb = "print";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.FileName = "C:\\Program Files\\Internet
Explorer\\iexplore.exe";
proc.StartInfo.Arguments = strFileName;
}

proc.Start();

if (!fPromptForPrinter)
{
StreamWriter myStreamWriter = proc.StandardInput;
myStreamWriter.WriteLine(strDefaultPrinter);

myStreamWriter.Close();
//proc.WaitForExit();
proc.Close();
}

for (; ;)
{
if (proc.HasExited)
{
break;
}
else
{
System.Windows.Forms.Application.DoEvents();
Thread.Sleep(1000);
}
}

In order to redirect standard in, I had to set UseShellExecute to false.
I believe this causes me to send IExplorer.exe as the filename with
arguments.

When I went this route, it appears that the print verb is ignored and that
IE is launched and will "open: the document. This is not good. I also tried
with the WindowStyle hidden and that was ignored.

So, is there any way to make this work as intended ? Is there a /P for
print (switch) or something that could be passed ?

Or is there another route that can solve this ? I have investigated other
strategies that don't use IE, but I have alot of time invested in getting the
HTML document just right and would like to work this out.

Thanks for the help.

Rick

P.S. I don't know what would be the best discussion group for this question.
Sheng Jiang[MVP]
2007-08-15 00:19:05 UTC
Permalink
I remember reading an article from kb about a limitation in printing to
prevent malicious web scripts launches denial of service attack to the
user's printer. Printing multiple pages programmatically without user's
interaction is not supported.

If your clients have Microsoft word installed, you can use word automation
to open and print the html files.
--
Sheng Jiang
Microsoft MVP in VC++
Post by RLubanovic
Hi,
I have been trying to solve a batch printing issue for a few weeks. I
have tried numerous strategies and have posted a few questions. I have not
This is a VB.Net 2.0 app, and it uses C# for the printing object.
There is a difference between printing one invoice or a batch.
When I print one invoice, I can use the "open" verb and allow IE to
launch. This is nice because it allows the user to print preview, select the
printer and print. Then they close IE and return to the app.
When I want to print a batch, I can select the printer ahead of time, then
call IE in a loop with the "print" verb and expect to print them all using
the default printer.
The issue is that IE wants to prompt me for the printer every time.
This
Post by RLubanovic
is not good.
I am attempting to redirect standard in to recieve the default printer
from a stream. In order to do this, I had to change the code to the
Process proc = new Process();
if (fPromptForPrinter)
{
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.Verb = "open";
proc.StartInfo.FileName = strFileName;
}
else
{
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle =
ProcessWindowStyle.Minimized;
Post by RLubanovic
proc.StartInfo.Verb = "print";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.FileName = "C:\\Program Files\\Internet
Explorer\\iexplore.exe";
proc.StartInfo.Arguments = strFileName;
}
proc.Start();
if (!fPromptForPrinter)
{
StreamWriter myStreamWriter = proc.StandardInput;
myStreamWriter.WriteLine(strDefaultPrinter);
myStreamWriter.Close();
//proc.WaitForExit();
proc.Close();
}
for (; ;)
{
if (proc.HasExited)
{
break;
}
else
{
System.Windows.Forms.Application.DoEvents();
Thread.Sleep(1000);
}
}
In order to redirect standard in, I had to set UseShellExecute to false.
I believe this causes me to send IExplorer.exe as the filename with
arguments.
When I went this route, it appears that the print verb is ignored and that
IE is launched and will "open: the document. This is not good. I also tried
with the WindowStyle hidden and that was ignored.
So, is there any way to make this work as intended ? Is there a /P for
print (switch) or something that could be passed ?
Or is there another route that can solve this ? I have investigated other
strategies that don't use IE, but I have alot of time invested in getting the
HTML document just right and would like to work this out.
Thanks for the help.
Rick
P.S. I don't know what would be the best discussion group for this question.
RLubanovic
2007-08-15 02:26:01 UTC
Permalink
Sheng,

You are correct. I saw a similar article on that conclusion and it was
confirmed by Microsoft today. I am going to attempt a solution using the web
browser control, but if that fails I will pursue your route. I do need to
render the HTML properly, I wasn't sure if that was possible with Word.

Thanks for the response,
Rick
Post by Sheng Jiang[MVP]
I remember reading an article from kb about a limitation in printing to
prevent malicious web scripts launches denial of service attack to the
user's printer. Printing multiple pages programmatically without user's
interaction is not supported.
If your clients have Microsoft word installed, you can use word automation
to open and print the html files.
--
Sheng Jiang
Microsoft MVP in VC++
Post by RLubanovic
Hi,
I have been trying to solve a batch printing issue for a few weeks. I
have tried numerous strategies and have posted a few questions. I have
not
Post by RLubanovic
This is a VB.Net 2.0 app, and it uses C# for the printing object.
There is a difference between printing one invoice or a batch.
When I print one invoice, I can use the "open" verb and allow IE to
launch. This is nice because it allows the user to print preview, select
the
Post by RLubanovic
printer and print. Then they close IE and return to the app.
When I want to print a batch, I can select the printer ahead of time,
then
Post by RLubanovic
call IE in a loop with the "print" verb and expect to print them all using
the default printer.
The issue is that IE wants to prompt me for the printer every time.
This
Post by RLubanovic
is not good.
I am attempting to redirect standard in to recieve the default printer
from a stream. In order to do this, I had to change the code to the
Process proc = new Process();
if (fPromptForPrinter)
{
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.Verb = "open";
proc.StartInfo.FileName = strFileName;
}
else
{
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle =
ProcessWindowStyle.Minimized;
Post by RLubanovic
proc.StartInfo.Verb = "print";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.FileName = "C:\\Program Files\\Internet
Explorer\\iexplore.exe";
proc.StartInfo.Arguments = strFileName;
}
proc.Start();
if (!fPromptForPrinter)
{
StreamWriter myStreamWriter = proc.StandardInput;
myStreamWriter.WriteLine(strDefaultPrinter);
myStreamWriter.Close();
//proc.WaitForExit();
proc.Close();
}
for (; ;)
{
if (proc.HasExited)
{
break;
}
else
{
System.Windows.Forms.Application.DoEvents();
Thread.Sleep(1000);
}
}
In order to redirect standard in, I had to set UseShellExecute to false.
I believe this causes me to send IExplorer.exe as the filename with
arguments.
When I went this route, it appears that the print verb is ignored and
that
Post by RLubanovic
IE is launched and will "open: the document. This is not good. I also
tried
Post by RLubanovic
with the WindowStyle hidden and that was ignored.
So, is there any way to make this work as intended ? Is there a /P for
print (switch) or something that could be passed ?
Or is there another route that can solve this ? I have investigated
other
Post by RLubanovic
strategies that don't use IE, but I have alot of time invested in getting
the
Post by RLubanovic
HTML document just right and would like to work this out.
Thanks for the help.
Rick
P.S. I don't know what would be the best discussion group for this
question.
Loading...