Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 931717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:33:03+00:00 2026-05-15T20:33:03+00:00

I am trying to print pdf, ppt, and word documents from my windows service

  • 0

I am trying to print pdf, ppt, and word documents from my windows service using ShellExecute.

Process printingProcess = new Process
                        {
                            StartInfo =
                                {
                                    FileName = filePath,
                                    WindowStyle = ProcessWindowStyle.Hidden,
                                    CreateNoWindow = true,
                                    UseShellExecute = true,
                                    Verb = "Print"
                                }
                        };
printingProcess.Start();

This works in most cases. But for word documents that are corrupt, the Process.Start method never completes and the service hangs.

Basically, word pops up the “bad document! repair” dialog. I want the service to identify that word is not playing nice and kill the process and proceed with the next document in its queue.

What should I do?

[UPDATE]

Guys, here is the code to reproduce the issue:

static void Main(string[] args)
{
    string filePath = @"d:\corruptdocument.docx";

    PrintDocument(filePath);

    Console.WriteLine("Completed!");
    Console.ReadKey();
}

private static void PrintDocument(string filePath)
{
    Process printingProcess = new Process
                                {
                                    StartInfo =
                                        {
                                            FileName = filePath,
                                            WindowStyle = ProcessWindowStyle.Hidden,
                                            CreateNoWindow = true,
                                            UseShellExecute = true,
                                            Verb = "Print"
                                        }
                                };
    using (printingProcess)
    {
        Console.WriteLine("Starting process...");
        printingProcess.Start();
        Console.WriteLine("Completed start...");
    }
}

And here is a screenshot : http://twitpic.com/23jwor

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:33:03+00:00Added an answer on May 15, 2026 at 8:33 pm

    Okay Guyz, here is what I found out!

    ShellExecute for word uses DDE. So the process.Start() method returns only after the command is complete (in my case, “printing the document”). [Not sure if this is accurate, but atleast that is my experience with word]

    So what are our options?

    1. As @Hans mentioned, use COM interop.
    2. Run the printing job in a seperate thread and wait for the thread to complete for a predefined interval and terminate the corresponding word process after this interval.

    I chose option 2 as I was dealing with other document types like PDF,PPT and I was too lazy to change the implementation! 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to print .pdf and .tif files using C# in windows application.
I'm trying to print Arabic in some PDF documents using the Java code found
I'm trying to print xls file to pdf using soffice on windows machine. i
I get this error when trying to print postscript created from a pdf using
I am trying to silent print PDF files from within a java application (more
I'm trying to use Ghostscript 9.02 on Windows 7 to print a PDF to
I'm trying to learn assembly using NASM, the pcasm-book.pdf from Dr Paul Carter -
I am trying to print Arabic text in cell inside table (in pdf) using
I'm trying to print the Paypal transaction ID on our invoice PDF files. Can
I am trying to print out true if there is such letter/word and false

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.