Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IE as a Windows Service???

Status
Not open for further replies.

protechdm

Programmer
Dec 30, 2001
36
GB
Hi,

Heres the plan :-

Transform some XML via XSLT and save the resulting HTML to a file in a certain folder.
Write a printing service that wraps a FileSystemWatcher monitoring the above folder for new HTML files.
Print the newly created HTML file.

If I run the code - contained in the sub below - in a normal .NET app it works fine and the HTML is sent to the printer. But when I implement it as a service as shown in the sub below all you get is a Windows Alert sound ( and obviously no message as it is a service nor any exception thrown. At first I thought it was because the thread had not finished processing before it was discarded but it isn't.

Any thoughts anybody? Cheers.

Private Sub SpoolFileSystemWatcher_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles SpoolFileSystemWatcher.Created
Try
Dim x As StreamReader = File.OpenText(e.FullPath)
Dim y As String = x.ReadToEnd()
x.Close()
test = New SHDocVw.InternetExplorerClass()
test.Navigate("about:blank")
test.Document.body.innerhtml = Trim(y)
test.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER)

Dim n As Integer
For n = 1 To 3000000

Next
Catch ex As Exception
If EventLog.SourceExists("spool") = False Then
EventLog.CreateEventSource("spool", "application")
End If
System.Diagnostics.EventLog.WriteEntry("spool", ex.Message, EventLogEntryType.Information)
End Try

End Sub
 
Make sure the user your service is running as has access to the folder where your files are. Typically, the default service user only has limited permissions to the machine.

Chip H.
 
No definitely has access - even wrote the HTML to the event viewer just to make sure!

I've scoured the net and even downloaded some code from Microsoft ( which didn't work ).

I know in the days of VB6 you could use the MSHTML and API call to print the document but there doesn't seem to be a way in VB .NET.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top