Mapping printer 
Author Message
 Mapping printer

Hi all

How do I with API map a printer (like Net Use LPT1: \\SERVER\PRINTQUE).

Brgs
Mike



Fri, 11 May 2001 03:00:00 GMT  
 Mapping printer
try the following:

'Map network printer, Windows
               Call Shell("rundll32.exe shell32.dll,SHHelpShortcuts_RunDLL
AddPrinter", _
                           vbNormalFocus)

              'Under Windows NT, it is possible to bring up a predefined
              'Windows Dialog box for connecting to a network printer -
              'the ConnectToPrinterDlg API. However, this dialog is not
              'accessible by Visual Basic programs running under
              'Windows 95. Therefore, you must use a Command line
              'equivalent statement to invoke the "Add Printer Wizard"
              'as detailed above.

Have fun!



Quote:
> Hi all

> How do I with API map a printer (like Net Use LPT1: \\SERVER\PRINTQUE).

> Brgs
> Mike



Mon, 14 May 2001 03:00:00 GMT  
 Mapping printer
Also you can try this, I've used it to map drives never to map printers,
but I believes it works

Add the following code to a BAS module:

Option Explicit

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

'----------------------------------------------
'WNetAddConnection2

'Allows the caller to redirect (connect) a local
'device to a network resource. It is similar to
'WNetAddConnection, except that it takes a pointer
'to a NETRESOURCE structure to describe the network
'resource to connect to. It also takes the addition
'parameters lpUserID and dwFlags.

'lpNetResource
'Specifies the network resource to connect to.
'The following fields must be set when making a
'connection, the others are ignored.

'  lpRemoteName: Specifies the network resource
'                to connect to. This is limited
'                to MAX_PATH.

'  lpLocalName: This specifies the name of a local
'               device to be redirected, such as "F:"
'               or "LPT1". The string is treated in a
'               case insensitive manner, and may be
'               the empty string (or NULL) in which
'               case a connection to the network resource
'               is made without making a redirection.

'  lpProvider: Specifies the NP to connect to. If NULL
'              or empty string, Windows will try each
'              NP in turn. The caller should set
'              lpProvider only if it knows for sure
'              which network it wants. Otherwise, it
'              is preferable to let Windows determine
'              which NP the network name maps to.
'              If this is non NULL, Windows will try
'              the named NP and no other.

'  dwType: Specifies the type of resource to connect to.
'          It must be RESOURCETYPE_DISK or RESOURCETYPE_PRINT
'          if lpLocalName is not the empty string. It may
'          also be RESOURCETYPE_ANY if lpLocalName is the
'          empty string.

'lpPassword
'Specifies the password to be used in making the
'connection, normally the password associated with
'lpUserID. A NULL value or string may be passed in
'to indicate to the function to use the current
'default password.
'
'lpUserID
'This specifies the identity of the user needed to
'make the connection. If NULL, a default will be
'applied. This is used when the user wishes to connect
'to a resource, but has a different user name or
'account assigned to him for that resource. This
'identification represents a security context, and
'is NP specific.
'
'dwFlags
'This is a bit mask which may have any of the
'following bits set:
'
'  CONNECT_UPDATE_PROFILE: If the connection should
'                          be made persistent. If set,
'                          Windows automatically restores
'                          this connection when the user
'                          logs on to the network. A connection
'                          is only made persistent if the
'                          connection was successful.

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 RESOURCE_CONNECTED = &H1
'Public Const RESOURCE_REMEMBERED = &H3
'Public Const RESOURCEDISPLAYTYPE_DOMAIN = &H1
'Public Const RESOURCEDISPLAYTYPE_GENERIC = &H0
'Public Const RESOURCEDISPLAYTYPE_SERVER = &H2
'Public Const RESOURCEUSAGE_CONTAINER = &H2

Public Const NO_ERROR = 0
Public Const CONNECT_UPDATE_PROFILE = &H1
Public Const RESOURCETYPE_DISK = &H1
Public Const RESOURCETYPE_PRINT = &H2
Public Const RESOURCETYPE_ANY = &H0
Public Const RESOURCE_GLOBALNET = &H2
Public Const RESOURCEDISPLAYTYPE_SHARE = &H3
Public Const RESOURCEUSAGE_CONNECTABLE = &H1

' -------- Form Code

   Dim NETR As NETRESOURCE
   Dim errInfo As Long

   With NETR
      .dwScope = RESOURCE_GLOBALNET
      .dwType = RESOURCETYPE_PRINT
      .dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
      .dwUsage = RESOURCEUSAGE_CONNECTABLE
      .lpRemoteName = "\\servername\device" ' Change This acording to your
needs
      .lpLocalName = "LocalName" ' Change This acording to your needs
   End With

   errInfo = WNetAddConnection2(NETR, vbNullString, "username",
CONNECT_UPDATE_PROFILE)



Quote:
> Hi all

> How do I with API map a printer (like Net Use LPT1: \\SERVER\PRINTQUE).

> Brgs
> Mike



Mon, 14 May 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. removing mapped printer in log-in script

2. Map printer driver (.drv) using LoadLibrary

3. I want to map a network printer to LPT1

4. Enumerate Current Network Drive and Printer Mappings:

5. printing graphic bit map to the printer

6. BMP output mapping BMP-pixel to printer-pixel 1:1

7. Help with Mapping of a dos printer for Terminal Server

8. Save/Restore printer-mappings

9. Is it possible to map a add Network printer with vbs

10. Mapping shared printers with a Logon Script.

11. Printer Mapped?

12. Win API to find if a Printer is mapped

 

 
Powered by phpBB® Forum Software