More on Controlling Windows Fax Services Using VB.Net
(Page 1 of 4 )
Welcome to the second part of this article about controlling Windows 2003 fax services through a Visual Basic.Net application. In this article, you'll learn how to get some information from a fax server and write it to a text file. You will also learn how to submit a job to a server.
Background
If you haven't already done the steps outlined in the first article you will need to complete those before you go any further. If you have already completed them you should have a working Windows 2003 fax server, and a Visual Basic project that can connect to this server using the fxscomex.dll library. At the moment the code we have written does not really do anything very useful; it just proves that we can connect to the server and view/change its properties.
Now Let's do Something Useful
As I just mentioned, the application at the moment won't really do anything useful. Here we are going to write some code that will get some status information off the fax server and write it to a text file. Add a new button to the project, and in its click event, place the following code. What the code is actually doing will be discussed shortly.
Dim objFaxServer As New FAXCOMEXLib.FaxServer 'Fax server object
Dim objFaxActivity As FAXCOMEXLib.IFaxActivity 'Fax activity Object
Dim collFaxDevices As FAXCOMEXLib.FaxDevices 'Fax devices object
Dim intTotJobCnt As Integer 'Job and device count
Dim objBalFileWritter As StreamWriter 'object to write text
'connect to the fax server.
objFaxServer.Connect("fax-server1")
'work out how many jobs are on the server by adding up the outgoing and queued
objFaxActivity = objFaxServer.Activity
'Refresh the activity object
objFaxActivity.Refresh()
'get the current numbers
intTotJobCnt = objFaxActivity.OutgoingMessages + objFaxActivity.QueuedMessages
'now write it out to the bal file along with the no of modems on this server
collFaxDevices = objFaxServer.GetDevices
'open the file for writing and put the message into it on a new line
objBalFileWritter = File.AppendText("c:num_jobs.log")
objBalFileWritter.WriteLine("Time:" & Now())
objBalFileWritter.WriteLine("Modems:" & collFaxDevices.Count)
objBalFileWritter.WriteLine("Total Faxes:" & intTotJobCnt)
objBalFileWritter.WriteLine("Outgoing: " & objFaxActivity.OutgoingMessages)
objBalFileWritter.WriteLine("Queued: " & objFaxActivity.QueuedMessages)
objBalFileWritter.WriteLine("Incoming: " & objFaxActivity.IncomingMessages)
objBalFileWritter.Close()
Next: What is the Code Doing? >>
More Visual Basic.NET Articles
More By Luke Niland