Results 1 to 4 of 4

Thread: Assigning a Network printer

  1. #1

    Thread Starter
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334
    What port should I use when trying to programmatically capture a network printer when using the following


    Code:
    Public Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" _
        (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long
    
    Public Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" _
        (lpNetResource As NETRESOURCE, _
        ByVal lpPassword As String, _
        ByVal lpUserName As String, _
        ByVal dwFlags As Long) As Long
    
    Public Const ERROR_NOT_CONNECTED = 2250&
    Public Const ERROR_EXTENDED_ERROR = 1208&
    Public Const ERROR_MORE_DATA = 234
    Public Const ERROR_ACCESS_DENIED = 5&
    Public Const ERROR_ALREADY_ASSIGNED = 85&
    Public Const ERROR_BAD_NET_NAME = 67&
    Public Const ERROR_BAD_DEV_TYPE = 66&
    Public Const ERROR_BUSY = 170&
    Public Const ERROR_CANNOT_OPEN_PROFILE = 1205&
    Public Const ERROR_DEVICE_ALREADY_REMEMBERED = 1202&
    Public Const ERROR_INVALID_PASSWORD = 86&
    Public Const ERROR_NO_NET_OR_BAD_PATH = 1203&
    Public Const ERROR_NO_NETWORK = 1222&
    
    
    Public Const RESOURCETYPE_ANY = &H0
    Public Const RESOURCETYPE_DISK = &H1
    Public Const RESOURCETYPE_PRINT = &H2
    
    Public Const CONNECT_UPDATE_PROFILE = &H1
    
    Public Type NETRESOURCE
            dwScope As Long
            dwType As Long
            dwDisplayType As Long
            dwUsage As Long
            lpLocalName As String
            lpRemoteName As String
            lpComment As String
            lpProvider As String
    End Type
    
    
    Dim lRes&
    Dim sUser$
    Dim udtNet As NETRESOURCE
    
    
     Command1_Click
    
    
    With udtNet
        
        Select Case cboRes.Text
            Case "DISK"
                .dwType = RESOURCETYPE_DISK
                .lpLocalName = "N:" & Chr(0)
                .lpRemoteName = "---------\c$" & Chr(0)
            Case "PRINTER"
                .dwType = RESOURCETYPE_PRINT
                .lpLocalName = <what goes here> & Chr(0)
                .lpRemoteName = InputBox("Printer") & Chr(0)
            Case "ANY"
                .dwType = RESOURCETYPE_ANY
                MsgBox "Not Allowed"
        End Select
           
        
        
    End With
        
    sUser = lblUser.Caption & Chr(0)
    
    Dialog.Show 1
    
    sPass = sPass & Chr(0)
    
    lRes = WNetAddConnection2(udtNet, ByVal sPass, ByVal sUser, ByVal CONNECT_UPDATE_PROFILE)
    
    
    lblRes.Caption = lRes
    
    
    End Sub
    Clearly it can't be LPT1. I can capture a network drive but I am stuck with the printer.
    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    From what I found in the msdn library, I think you can pass vbNullString. Or if you want to print from DOS programs, you can redirect the local LPT1 to the network printer.
    This is a part of what I found in the MSDN library:

    You must specify the following members of the NETRESOURCE structure:
    dwType: Specifies the type of network resource to connect to. If lpLocalName points to a non-empty string, this member can be RESOURCETYPE_DISK or RESOURCETYPE_PRINT. If
    lpLocalName is NULL or points to an empty string, dwType can be RESOURCETYPE_DISK, RESOURCETYPE_PRINT, or RESOURCETYPE_ANY.

    lpLocalName: Points to a null-terminated string that specifies the name of a local device to be redirected, such as "F:" or "LPT1". The string is treated in a case-insensitive manner. If the string is empty or lpLocalName is NULL, the function makes a connection to the network resource without redirecting a local device.

    lpRemoteName: Points to a null-terminated string that specifies the network resource to connect to. The string can be up to MAX_PATH characters in length. The string must follow the network provider's naming conventions.

    lpProvider: Points to a null-terminated string that specifies the network provider to connect to. If lpProvider is NULL or points to an empty string, the operating system attempts to determine the correct provider by parsing the string pointed to by lpRemoteName.
    You should set this member only if you know for sure which network provider you want to use. Otherwise, let the operating system determine which provider the network name maps to.
    If this member is not NULL, the operating system attempts to make a connection only to the named network provider.

  3. #3

    Thread Starter
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334

    Question Assigning lpLocalName

    Yes but I want the network resource (printer) to appear in the users printers folder - if I assign a network drive it appears in explorer. If the printer is assigned with

    Code:
        lpLocalName=chr(0)
    then there is no local (logical or otherwise) device assigned.
    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



  4. #4
    Fanatic Member Gary.Lowe's Avatar
    Join Date
    May 2000
    Location
    In my sphere of influence
    Posts
    621
    Hmmm


    Grouper I have foiled you plan to take over every printer in our office and print hundreds and hundreds of SClub7 song lyric copies (seeing as it is your favorite band)

    Haa Haaa!!

    Gary Lowe
    VB6 (Enterprise) SP5
    ADO 2.6
    SQL Server 7 SP3

    OK I know my spelling and grammer is crap so don't quote me on it!

    To err is human to take the P! is only natural !!

    Click on the top section of image for Marcus Miller website and bottom section of image for 'Run For Cover' sound clip


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