-
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.
-
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.
-
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
then there is no local (logical or otherwise) device assigned.
-
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!!