Results 1 to 3 of 3

Thread: Setting default printer on NT4

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    UK
    Posts
    66

    Post

    After searching through the site I can't find anywhere any code that will let me set the default printer for an NT4 Workstation using VB5!

    I want something along the lines of

    If machinename = "Rm10-17" then
    setdefaultprinter = "Room 10 printer"
    EndIF

    Any ideas?

    Simon

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

    Post

    Try something like this:
    Code:
    Private Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
    
    Private Sub Command1_Click()
        Dim prn As Printer
        Dim blnIsFound As Boolean
        Dim strBuffer As String
        
        If machinename = "Rm10-17" Then
            strBuffer = "Room 10 printer"
        
            'Check if the printer exists
            For Each prn In Printers
                If UCase(strBuffer) = UCase(prn.DeviceName) Then
                    strBuffer = strBuffer & "," & prn.DriverName & "," & prn.Port
                    blnIsFound = True
                    Exit For
                End If
            Next
            'If printer exists, then change it to be default
            If blnIsFound Then
                Call WriteProfileString("windows", "device", strBuffer)
                MsgBox "Succesfully changed printer " & strCommand
                End
            End If
        End If
    End Sub
    Assuming that the "Room 10 printer" is a valid printer.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    UK
    Posts
    66

    Post

    Thanks Serge! I look forward to trying it on Monday morning

    Simon

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