views:

1174

answers:

2

I'm printing a document by creating a System.Diagnostics.Process object and then setting the StartInfo verb to "print", then calling the process Start() method.

I want this print process to be hidden, so I'm setting CreateNoWindow = true and WindowStyle = ProcessWindowStyle.Hidden. But the application (Word or Acrobat) still appears during the printing.

I know that the hidden process settings are ignored if a username or password is set for the process and I've debugged through and verifyied they are empty. I've even tried explicitly setting them to NULL to no avail.

I'm wondering if the action of printing makes the application behave as if it requires user intervention (Word displays a "printing document.." dialog box) which negates the settings to hide it.

I'm using .Net 2.0, C#, Word 2007 and Windows Vista.

My actual code is as follows:

System.Diagnostics.Process shellProcess = new System.Diagnostics.Process();
shellProcess.StartInfo.FileName = fullFileName;                   
shellProcess.StartInfo.CreateNoWindow = true;
shellProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
shellProcess.StartInfo.Verb = "print";
shellProcess.Start();

Help is really appreciated...

Note that I'm aware that I can use the Word or Acrobat API to achive the same thing but this question is specifically about the visibility of the shell process.

+1  A: 

If you want to print a Word document without Word actually appearing in a window, you'll want to use Office Automation instead. Microsoft makes Office Automation assemblies available (I think they are installed with Office by default.) Here is an article on how to do that. I haven't actually tried the code but I've done some automation and it looks good from a quick read.

Here is an article from Microsoft on Office Automation.

Dave Swersky
+1  A: 

The StartInfo.WindowStyle is passed to the application and the application can do whatever it wants with it (it can use it or ignore it).

And I'm not sure but I think CreateNoWindow only applies to console applications.

Once a process is started you have no control over it and that process can show whatever UI it wants, you're best bet is to use the specific program option (for Office use automation like Dave suggested, I don't know about Acrobat).

Nir