Results 1 to 5 of 5

Thread: Which one is Default Printer?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 1999
    Location
    Scarsdale, NY
    Posts
    26

    Post

    Hi!

    Does anyone know how I can check which printer is set as default? Is there an API that does it?

    I also need to find a way of closing a printer. Again, is there an API that does that?

    Thank you! Thank you!

    Olga

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    The Printer Object Defaults to the Default Printer when your Application Starts.

    Can you explain what you mean by Closing a Printer?

    You finish a Print by Issuing Printer.EndDoc, or Cancel the Last Page by Issuing Printer.KillDoc

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  3. #3
    Guest

    Post

    i forgot where i got this but it works
    and you can modify it for what you need:

    This tip uses the registry to get the current printer name. Make a new project and add a form. To the form add a command button. Copy the following code into the form's General Declarations procedure:

    'Declarations
    Private Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwReserved As Long, ByVal samDesired As Long, phkResult As Long) As Long
    Private Declare Function RegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName$, ByVal lpdwReserved As Long, lpdwType As Long, lpData As Any, lpcbData As Long) As Long
    Private Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long

    Const HKEY_CURRENT_CONFIG As Long = &H80000005

    Function RegGetString$(hInKey As Long, ByVal subkey$, ByVal valname$)

    'Needed declarations
    Dim RetVal$, hSubKey As Long, dwType As Long, SZ As Long
    Dim R As Long

    RetVal$ = ""

    Const KEY_ALL_ACCESS As Long = &HF0063
    Const ERROR_SUCCESS As Long = 0
    Const REG_SZ As Long = 1

    'Open the key
    R = RegOpenKeyEx(hInKey, subkey$, 0, KEY_ALL_ACCESS, hSubKey)

    If R <> ERROR_SUCCESS Then GoTo Quit_Now

    SZ = 256: v$ = String$(SZ, 0)
    R = RegQueryValueEx(hSubKey, valname$, 0, dwType, ByVal v$, SZ)

    If R = ERROR_SUCCESS And dwType = REG_SZ Then
    RetVal$ = Left$(v$, SZ - 1)
    Else
    RetVal$ = "--Not String--"
    End If

    If hInKey = 0 Then
    R = RegCloseKey(hSubKey)
    End If

    Quit_Now:
    RegGetString$ = RetVal$
    End Function

    Private Sub Command1_Click()
    Dim GetCurrPrinter As String

    GetCurrPrinter = RegGetString$(HKEY_CURRENT_CONFIG, "System\CurrentControlSet\Control\Print\Printers", "Default")
    MsgBox GetCurrPrinter
    End Sub

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 1999
    Location
    Scarsdale, NY
    Posts
    26

    Post

    Aaron,
    Here's what I need to do:
    I have several network printers attached to the computer. I need to use AcrobatPDFWriter printer. So, I need to figure out which printer is currently set as default, put it into a variable, do printing using AcrobatPDFWriter printer, and then set printer back the way it was.
    Also, when I'm done printing, the little print icon stays in my status bar with status "Paused". I need it out of there!

    Larryn,
    Thanks for your code. Unfortunately, it doesn't work for me. When I get to
    "Quit_Now:", RetVal$ is empty.

  5. #5
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Here's a Function I wrote which will search the Printers for the specified Devicename of the Printer you want to use.
    If it's found the Function will return the Current Printer Devicename and Change to the Specified Printer.

    To Restore the Original/Default Printer, just call the Function again with the Initially returned Devicename, eg.
    Code:
    Private Sub Command1_Click()
        Dim sDefault As String
        'Select New Printer
        sDefault = SelectPrinter("Generic / Text Only")
        If Len(sDefault) Then
            'Do Print Here
            'Select Original Printer
            Call SelectPrinter(sDefault)
        Else
            'Printer Not Found
            MsgBox "Printer not Found"
        End If
    End Sub
    
    Private Function SelectPrinter(ByVal sDeviceName As String) As String
        'Enumerates the Printers looking for the specified
        'Devicename, if found, returns the Current Printer Devicename
        'Prior to changing Printers.
        Dim oPRN As Printer
        For Each oPRN In Printers
            If oPRN.DeviceName = sDeviceName Then
                SelectPrinter = Printer.DeviceName
                Set Printer = oPRN
                Exit For
            End If
        Next
    End Function

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width