question

Chris-5779 avatar image
0 Votes"
Chris-5779 asked ·

Printing rendered HTML from Windows Service

I am attempting to maintain an automated html printing service and we are migrating to Server 2016. During this migrating, the automated printer service has stopped functioning.

The original version used the 'old standard' of creating an InternetExplorer interface, and then controlling it remotely using the OLECMD method. I've tried including the code, but every time I do I get an Azure firewall error when trying to save the question. It's easy enough to find though, comes up whenever you search "Print html from windows service."

While executing on Server 2003 or Windows 10, this works just fine. But the moment I put it on Server 2016, it reaches the 'Print' OLECMD and never comes back. No error is thrown, it simply goes to sleep waiting for the teardown to happen, and that never does.

Things I have already tried and have not worked...

  • Giving the Windows Service permission to interact with the desktop

  • Changing the user the Service runs under to both system and administrative accounts--none worked

  • Going into Component Services and giving blanket access/control/launch/activation permissions to everything (planned to narrow it once I knew what it needed) related to Internet Explorer

  • Taking ownership of everything related to IE in the Windows Registry

  • Replacing the OLECMD logic with a Windows Forms Browser control and trying to remote control that. It works while in a console app, but fails once put into a Windows Service

  • Doing the same as above, but spawning the Browser Control off in an STA apartment stated thread

  • Attempting all three of my printing options (OLECMD, Forms, and Threaded Forms) in a Scheduled Task

  • Making use of Foxxit PDF Reader's ability to run headless (this was axed by leadership/legal before I got the chance to try it)

I have seen advice around the net advising that the "recommended" way of having a hands-off printing service is to run it as a tray application, but that is an unacceptable solution in our environment. Unless I'm missing something big, you can't activate a tray application unless someone has logged in--and given the sheer volume of printing that we handle, we need a dedicated server handling this. Which means that nobody works on that server, and so nobody is reliably logged into it. Likewise, just using Windows 10 is unacceptable in the environment we're working with.

Ultimately, the problem seems to stem from Microsoft's increasing levels of Session 0 Isolation...and it appears that, unless I'm missing something that I can't find documented anywhere on the net, that the old OLECMD system has been locked out of being able to command a Print operation while in session 0.

So, is there something I am missing that I couldn't find anywhere else on the internet that makes this work? Or is there some other recommended way of having something that prints rendered HTML in an entirely hands-off fashion?

dotnet-csharpwindows-server-2016
· 2
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,

Just checking in to see if the information provided was helpful.

If the reply helped you, please remember to accept as answer.
If no, please reply and tell us the current situation in order to provide further help.

0 Votes 0 ·

@Chris-5779
Hi,

We have not get information from you for several days.

If the other's reply is useful for you, please accept as answer. It will be helpful to other members who have same questions.
If you have any other confuse, please reply to us directly.

0 Votes 0 ·
JennyFeng-MSFT avatar image
1 Vote"
JennyFeng-MSFT answered ·

Hi,
I did research on this question, but I feel sorry that this question is hard to answer.
Windows server community usually discussing windows server built-in functions and related issue, for printing html question you'd better open a support ticket with Microsoft for deep research:
https://support.microsoft.com/en-gb/gp/contactus81?forceorigin=esmc&Audience=Commercial&wa=wsignin1.0

Hope above information can help you.

============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Unfortunately, I don't have $500 in my back pocket to pay Microsoft for Professional Services, which is what that link requires of me.

0 Votes 0 ·
cheong00 avatar image
0 Votes"
cheong00 answered ·

Try the following and see if it works for you:
1) Run the service as a standard user, with target printer configured.
2) In your service, run LoadUserProfile() API before printing. Remember to call UnloadUserProfile() after finish or the user profile can be corrupted. Strongly recommended to put it in your finally statement.

Here's example on how to call it in VB.NET, which should be easy to convert to C# once you copied the function/struct signature included in P/Invoke website. There are other examples in C# but I choose this one mainly because it uses WindowsIdentity.GetCurrent.Token directly instead of LogonUser() in most example, and this is more suitable for you. Just fill the PROFILEINFO as instructed and call it and you should be fine.


· 2 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Unfortunately, this does not seem to be able to get past a Service's Session 0 Isolation. My problem isn't that there is some specific printer I can't access, my problem is that I ask an emulated IE to print, and it refuses to do so.

0 Votes 0 ·

With the point that "But the moment I put it on Server 2016, it reaches the 'Print' OLECMD and never comes back. No error is thrown, it simply goes to sleep waiting for the teardown to happen, and that never does.", I guess there may not be handler for OLECMDID_PRINT in the running environment of your service.

Just to test, can you use Process.Start("print <path to some .txt file>") and see if it can print correctly?

If it can, then the problem would be on the rendering side, so as to narrow down the problem.

0 Votes 0 ·