Atlanta Custom Software Development 

   Search        Code/Page

User Login



Forgot the Password?
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
» Regular Expr Tester
» Free Tools

Get the Default Printer

Total Hit ( 4607)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article



API Declarations

Click here to copy the following block
Option Explicit

'MS Windows API Function Prototypes
Private Declare Function GetProfileString Lib "kernel32.dll" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long


Click here to copy the following block
' Retreive the vb object "printer" corresponding to the window's
' default printer.
Public Function GetDefaultPrinter() As Printer
  Dim strBuffer As String * 254
  Dim iRetValue As Long
  Dim strDefaultPrinterInfo As String
  Dim tblDefaultPrinterInfo() As String
  Dim objPrinter As Printer

  ' Retreive current default printer information
  iRetValue = GetProfileString("windows", "device", ",,,", strBuffer, 254)
  strDefaultPrinterInfo = Left(strBuffer, InStr(strBuffer, Chr(0)) - 1)
  tblDefaultPrinterInfo = Split(strDefaultPrinterInfo, ",")
  For Each objPrinter In Printers
    If objPrinter.DeviceName = tblDefaultPrinterInfo(0) Then
      ' Default printer found !
      Exit For
    End If
  ' If not found, return nothing
  If objPrinter.DeviceName <> tblDefaultPrinterInfo(0) Then
    Set objPrinter = Nothing
  End If
  Set GetDefaultPrinter = objPrinter
End Function


Click here to copy the following block
'- Start a new project and on the form_load event write this code
Private Sub Form_Load()
  Dim objPrinter As Printer

  Set objPrinter = GetDefaultPrinter()
  MsgBox "Default printer is: " + objPrinter.DeviceName
  MsgBox "Driver name is: " + objPrinter.DriverName
  MsgBox "Port is: " + objPrinter.Port
  Set objPrinter = Nothing
End Sub

Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with, SQL Server and other MS technologies. He is, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )

Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.