473,394 Members | 1,738 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,394 software developers and data experts.

process class to print word document and pass in printer

Can anyone tell me how to set the printer using the process class in VB.net,
I've tried everything, it always goes to the default printer.

My Code:

Dim pathToExecutable As String = "WINWORD.EXE"

Dim SPrinter = \\PrinterPath\PrinterName 'Name Of printer

Dim sReport = "C:\WordDoc1.doc" 'Complete name/path of PDF file

Dim starter As New ProcessStartInfo(pathToExecutable, "/t " + sReport + " "
+ SPrinter + "")

Try

Dim MyProcess As New Process

'MyProcess.StartInfo.Arguments = "/t " + sReport + " " + SPrinter + ""

MyProcess.StartInfo.CreateNoWindow = False

MyProcess.StartInfo.Verb = "print"

MyProcess.StartInfo.FileName = sReport

'MyProcess.StartInfo = starter

MyProcess.Start()

Dim iloop As Int16 = 0

If MyProcess.HasExited = False Then

'if not then loop for 100 time to try and close the process'with 10 seconds
delay

While Not MyProcess.HasExited

System.Threading.Thread.Sleep(10000)

MyProcess.CloseMainWindow()

iloop = CShort(iloop + 1)

If iloop >= 100 Then

Exit While

End If

End While

End If

MyProcess.WaitForExit(100000)

MyProcess.CloseMainWindow()

MyProcess.Close()

Thanks in advance,

Rick


Jul 25 '08 #1
1 6653
I figured it out:
Dim objStartInfo As New ProcessStartInfo

Dim objProcess As New System.Diagnostics.Process

Dim sreport as string = "c:\reportname.doc"

Dim sPrinter as string \\printerpath\printname

Try

objProcess.StartInfo.CreateNoWindow = True

objProcess.StartInfo.UseShellExecute = True

objProcess.StartInfo.FileName = sreport

objProcess.StartInfo.Arguments = """" & sPrinter & """"

objProcess.StartInfo.Verb = "PrintTo"

objProcess.StartInfo.CreateNoWindow = True

objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden

objProcess.Start()

Dim iloop As Int16 = 0

If objProcess.HasExited = False Then

'if not then loop for 100 time to try and close the process'with 10 seconds
delay

While Not objProcess.HasExited

System.Threading.Thread.Sleep(10000)

iloop = CShort(iloop + 1)

If iloop >= 100 Then

Exit While

End If

End While

End If

objProcess.Close()

objProcess.Dispose()

objProcess = Nothing

Catch ex As Exception

'MsgBox(ex.Message)

End Try

"Rick" <rf*****@newsgroups.nospamwrote in message
news:u1**************@TK2MSFTNGP02.phx.gbl...
Can anyone tell me how to set the printer using the process class in
VB.net, I've tried everything, it always goes to the default printer.

My Code:

Dim pathToExecutable As String = "WINWORD.EXE"

Dim SPrinter = \\PrinterPath\PrinterName 'Name Of printer

Dim sReport = "C:\WordDoc1.doc" 'Complete name/path of PDF file

Dim starter As New ProcessStartInfo(pathToExecutable, "/t " + sReport + "
" + SPrinter + "")

Try

Dim MyProcess As New Process

'MyProcess.StartInfo.Arguments = "/t " + sReport + " " + SPrinter + ""

MyProcess.StartInfo.CreateNoWindow = False

MyProcess.StartInfo.Verb = "print"

MyProcess.StartInfo.FileName = sReport

'MyProcess.StartInfo = starter

MyProcess.Start()

Dim iloop As Int16 = 0

If MyProcess.HasExited = False Then

'if not then loop for 100 time to try and close the process'with 10
seconds delay

While Not MyProcess.HasExited

System.Threading.Thread.Sleep(10000)

MyProcess.CloseMainWindow()

iloop = CShort(iloop + 1)

If iloop >= 100 Then

Exit While

End If

End While

End If

MyProcess.WaitForExit(100000)

MyProcess.CloseMainWindow()

MyProcess.Close()

Thanks in advance,

Rick


Jul 28 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: MouseHart | last post by:
I've written a simple program in VB 6.0 to list all my MP3 files. To show them on the screen I used an MSFlexGrid named TextGrid (which is not associated with any table or text file) in the...
0
by: Andy Newland | last post by:
Hi Guys, I would like to print out a word document using a VB .NET component. I have got VBA and VB.Net talking to each other and can pass word objects between COM and .NET. My reason for...
1
by: Fei Yuan | last post by:
Please forgive me re-posting this question since I wasn't clear in my original post. --------> Starting an external process needs to pass it a ProcessStartInfo() object. ProcessStartInfo has a...
0
by: srivalli chavali via DotNetMonster.com | last post by:
Hi, I have to print a word document using C#.NET. I also have to customize the printing option, the Printer tray, programmatically. So, I have used the PrintDocument class available in C#....
5
by: Dino M. Buljubasic | last post by:
I'd like to be able to print my form or some controls on it. I have found lots of references for this but they all talk about printing a text document from a form. Any help will be appreciated...
8
by: Philip Wagenaar | last post by:
I need to send printjobs to a printqueue under diffrent usernames. The printsoftware on the queue is not very 'secure' so I can create a user on 1 system and send a printjob under it's name to the...
9
by: Scott M | last post by:
I'm printing a directory of about 500 multi-page tifs to a high speed printer and the spooler process is killing me!!! here is a little code..... Public Function PrintImage(ByVal...
5
by: Raman | last post by:
Hello friends, I want to print an ID card. I have one Windows Form that contains front and back side. The printer is printing both front and back side at a time. I am trying to send both sides...
24
by: Tony Girgenti | last post by:
Hello. Developing a Windows Form program in VS.NET VB, .NET Framework 1.1.4322 on a windows XP Pro, SP2. Before printing a document, i want to set the font to a font that is only available...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.