VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

VB.NET Source Code


Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 340,156 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 3,996 people online right now. Registration is fast and FREE... Join Now!




Add a Network Printer

This snippet fills the gap on how to Add a Network Printer in VB.NET, accessing the PrintUIEntry object in printui.dll.

Submitted By: RodgerB
Actions:
Rating:
Views: 7,342

Language: VB.NET

Last Modified: December 1, 2007
Instructions: 1) Copy and Paste the subroutine into a class.
2) Read how to call the function.

Snippet


  1. ''' <summary>
  2. ''' Adds a Network Printer to the computer
  3. ''' </summary>
  4. ''' <param name="printerName">Name of the Printer you'd like to add</param>
  5. ''' <param name="networkPath">The path of the networked printer</param>
  6. ''' <param name="useExistingDriver">Don't overwrite existing driver</param>
  7. ''' <param name="setDefaultPrinter">Set as the default printer</param>
  8. ''' <remarks></remarks>
  9.  
  10. Public Shared Sub AddNetworkPrinter(ByRef printerName As String, ByRef networkPath As String, _
  11.         Optional ByRef useExistingDriver As Boolean = 0, Optional ByRef setDefaultPrinter As Boolean = 0)
  12.        
  13.         Dim cmdToSend As String = "rundll32 printui.dll,PrintUIEntry /in /m " & Chr(34) & printerName & Chr(34) & " /f " & networkPath
  14.         If useExistingDriver Then cmdToSend += " /u" '  /u = use the existing printer driver if it's already installed
  15.         If setDefaultPrinter Then cmdToSend += " /y" '  /y = set printer as the default
  16.         Shell(cmdToSend, AppWinStyle.Hide) ' execute the command
  17.  
  18. End Sub
  19.  
  20. ' Example of how to use this subroutine:
  21. AddNetworkPrinter("HP LaserJet 1320 PCL 6", "//myserver/Printer", True, True)

Copy & Paste


Comments

There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month