tags:

views:

384

answers:

1

I am creating a Windows Application in c# which can print a .html file every after 15 mins and it's working good.

Now when the system is going in sleep mode the application also sleeps. So i am creating a new Windows Service for the same job.

The service also working good but when the print event fires, a print dialog box appears on the screen and asking for print.

But i don't need the print dialog box because this service will work as unattended. So please give me some idea.

I am using this code within the service for print.

private void print()

    {
        object empty = null;
        axW.Navigate("http://www.google.com", ref empty, ref empty, ref empty, ref empty);
        for (; axW.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE; )
        {
            System.Windows.Forms.Application.DoEvents();
        }
        axW.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, ref empty, ref empty);
    }


public void printdoc()

    {
        try
        {
            Process printjob = new Process();
            printjob.StartInfo.FileName = @"C:\printdoc.html";
            printjob.StartInfo.UseShellExecute = true;
            printjob.StartInfo.Verb = "print";
            printjob.StartInfo.CreateNoWindow = true;
            printjob.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

            printjob.Start();
        }
        catch (Exception exc)
        {
            Function.LogErrorToFile("Print", exc.Message, true);
        }
    }