how to map/unmap printers using a batch file.

Posted on 2008-11-11
Last Modified: 2012-05-05
hi all,

just a quick one.

i am trying to map and unmap printers using a batch file. i cant find any info on this so could someone point me in the right direction!

rundll32 printui.dll,PrintUIEntry /q /gd /n\\printscanserver\transport laser

this doesnt work for unmapping the printer!

can i do anything else that i can add into my batch file?

Question by:Goption
    LVL 13

    Assisted Solution

    create a batch file and call it printers.bat (or anything!)

    START \\servername\Printername1
    START \\servername\Printername2

    Copy file to a share on a server and then add a line in the logon scripts to run the batch file.

    login script

    net use M: \\ServerName\Sharename
    LVL 57

    Expert Comment

    by:Pete Long

    Use Con2prt
    Rem ** Example Printers.bat file **
    Rem ** Adds network printers to Windows NT/2000/XP clients**
    Rem    To be run from the login script via "call \\server1\share\printers.bat" command.
    Rem    The &Location% environment variable is machine specific and needs to be defined manually on each machine
    Rem    either via Control Panel | System | Advanced | Environment Variables | System Variables
    Rem    or by creating the following String registry key on each machine:
    Rem      [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
    Rem      "Location"="Room23"
    \\server1\share\CON2PRT /F
    IF %Location% == Room23 \\server1\share\CON2PRT /CD \\dc1\Room23
    IF %Location% == Room23 \\server2\share\CON2PRT /C \\dc1\Room43
    /CD = Connect and make default
    /C = Connect only

    LVL 82

    Accepted Solution

    If you insist on rundll32, try "/dn" instead of "/gd", and put share names containing spaces in quotes:
    rundll32 printui.dll,PrintUIEntry /q /dn /n "\\printscanserver\transport laser"

    And as much as I used to love con2prt.exe, it's pretty hard to find nowadays, as it was part of the NT4 Zero Administration Kit; this website is long since dead.
    As replacement, there are a bunch of printer management VB scripts (try "dir p*.vbs") in the %systemroot%\system32 folder. These are better suited for logon scripts than rundll32, because they're not GUI oriented. The one you need is prnmngr.vbs:
    cscript prnmngr.vbs /?
    will give you some examples for usage.
    LVL 1

    Author Closing Comment

    thanks for your help it worked a treat!

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
    Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
    This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
    This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now