Results 1 to 4 of 4

Thread: help with printer object

  1. #1
    Guest

    Post

    trying to write a small program
    that will change the default printer
    at the command line..

    eg: c:\dp LaserJet4

    dp the name of my program
    and LaserJet4 in the list
    of my printers...


    here is what i have but it
    doesn't work...

    any suggestions greatly appreciated.

    Private Sub Form_Load()
    Dim Prntr As Printer
    Dim PrinterName As String
    Dim CommandLine As String
    Dim subc1 As String * 10
    Dim subc2 As String * 10

    Me.Hide

    CommandLine = Command$
    subc1 = InStr(1, CommandLine, subc2, vbTextCompare)
    If subc1 <> 0 Then
    PrinterName = subc1 'new default

    For Each Prntr In Printers
    If Prntr.DeviceName = PrinterName Then
    Set Printer = Prntr
    Exit For
    End If
    Next
    Else
    End If
    Unload Me
    End Sub

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Sure. Try something like this:

    Code:
    Option Explicit
    Private Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
    
    Private Sub Form_Load()
        Dim strCommand As String
        Dim prn As Printer
        Dim blnIsFound As Boolean
        Dim strBuffer As String
        
        strCommand = Command
        If Len(strCommand) = 0 Then
            MsgBox "You must specify the Printer Name."
            End
        End If
        
        For Each prn In Printers
            If UCase(strCommand) = UCase(prn.DeviceName) Then
                strBuffer = strCommand & "," & prn.DriverName & "," & prn.Port
                blnIsFound = True
                Exit For
            End If
        Next
        
        If blnIsFound Then
            Call WriteProfileString("windows", "device", strBuffer)
            MsgBox "Succesfully changed printer " & strCommand
            End
        End If
    End Sub
    Then you can call your program like this:


    C:\DP HP DeskJet 680C


    ------------------

    Serge

    Senior Programmer Analyst
    [email protected]
    [email protected]
    ICQ#: 51055819

    [This message has been edited by Serge (edited 02-11-2000).]

  3. #3
    New Member
    Join Date
    May 2000
    Posts
    15

    Question

    hello

    Serge,

    the above code worked great to SET the default printer, but
    how to GET the windows default printer from the registry

    regards

    zdocteur

  4. #4
    New Member
    Join Date
    May 2000
    Posts
    15

    Talking

    hi

    thanks Serge but i think i found the answer here:

    http://support.microsoft.com/support...-US&SD=gn&FR=0

    regards

    zdocteur

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