473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to print HTML programmatically from a windows service

Hello all,
I have a windows application that programmatically sends an html document to the printer using the AxSHDocVw.AxWebBrowser object. The application works beautifully. I tried to convert it to a windows service, and the application stopped working. I'm assuming because in my code I first Navigate to the document, and then print it --> since a service runs under a different context, the navigation/printing fails.

I tried to schedule the application using the task scheduler, and the code only works (i.e. documents print) when I'm logged in. Once I log off, the application runs, but fails on the Navigate function:

System.InvalidCastException: QueryInterface for interface SHDocVw.IWebBrowser2 failed.
at SHDocVw.IWebBrowser2.Navigate(String URL, Object& Flags, Object& TargetFrameName, Object& PostData, Object& Headers)
at AxSHDocVw.AxWebBrowser.Navigate(String uRL, Object& flags, Object& targetFrameName, Object& postData, Object& headers)

Do you guys know how I can get around this?

Thanks
kmsultan
Jan 19 '07 #1
3 5641
Not sure what happened, but the code is now working!

I was able to create a windows .NET service that calls the windows application which has the web browser. When I made the service interact with the desktop (in the properties of the service), everything worked perfectly.

I had to remove all Msgbox windows from my appliation, since the application is running in the .NET service context, and does not display windows/forms/etc on the screen.

The application get called, and executes even when no user is logged on.

Just thought I should share in case anyone else is having this problem.

Thanks
Jan 24 '07 #2
kenobewan
4,871 Expert 4TB
Well done kmsultan1! It is amazing the power of asking questions, even if someone else doesn't reply the mere asking makes it objective. Socrates was the master of asking and refining questions. That's why sometimes we should ask why someone is trying to do something...

Anyway, thanks for letting us know the solution :).
Jan 25 '07 #3
Hi kmsultan,

I am having problem while printing html page programatically using c#. Can you give me quick glance how you are working? I am trying to use webbrowser control but because I need to print in background thread but webbrowser control seems to work only in STA.

regards,

Bibek Dawadi
May 25 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Vince Keller | last post by:
I dont know if this is the correct newsgroup to post questions on Windows Service. I am trying to install and uninstall a Windows Service programmatically. As far as I know, there isnt a class...
9
by: Hardy Wang | last post by:
Hi all: I read an article from http://www.c-sharpcorner.com/Code/2003/Sept/InstallingWinServiceProgrammatically.asp about how to install a windows service programmatically. Based ont the code...
3
by: David Cho | last post by:
I am still struggling with this. Used the PrintDocument class, but it was printing gobblygook. Does not recognize the PDF files as Acrobat files and just prints text. Can't get the shell...
3
by: Alexander Wehrli | last post by:
Hi, I have a string containing an HTML formatted report. I want to print the interpreted "Website" defined by this string. How can I acheive this? Regards Alexander
5
by: Tony | last post by:
Every 10 seconds I need to search a SQL table for orders to print. The orders are created through WebForms on ASP.NET clients. The orders should not print until 10 minutes before they are due. ...
0
by: jigsmshah | last post by:
i am working on a project (windows service using VB.Net and C#) which gets the check details and check images from the database and prints the check to a printer. Printer name is configured in a...
1
by: =?Utf-8?B?S3VtYXIuQS5QLlA=?= | last post by:
We have a requirement in our project to print Html page from a vb.net windows service application. The application should not display any dialog box. The Printer details, which varies for different...
0
by: EricJudge06 | last post by:
We are converting some reports from Crystal Reports to Microsoft SQL Reporting Services (SSRS) in an ASP 2.0 VB.Net web app. Crystal had a function called PrintToPrinter which was being used to...
2
by: MalikTahirMahmood | last post by:
Hi, i am developing a car rental application, in which i required to get data from "salik Web site" UAE Toll system, I created one Desktop application in which i placed on webbrowser control and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.