Script/Batch to map Network printer


Recommended Posts

I'm trying to set up a local logon script to map a network printer (has a UNC of \\server1\Lexmark).

The problem is that due to the configuration of the network (out of my hands), the printer requires a username and password (for the sake of examples, let's assume the username is "Name" and the password is "Pass") every logon.

The simple workaround is to browse to the UNC address of the printer every login, and enter the username and password into the prompt. This is a massive inconvenience however.

I'm hoping that via a logon script, the printer will be remapped automatically every logon.

I am aware of the Net Use and the other common methods for mapping a network printer, however I do not know any that allow the username and password to be passed via the logon script/batch.

(Security of the username and password is not an issue. The account used for this is a limited account with pretty much only local printer access).

Link to comment
https://www.neowin.net/forum/topic/392794-scriptbatch-to-map-network-printer/
Share on other sites

you can try modifying this script.. i took from computerperformance.co.uk

it was a script to map a network drive, i edited for a printer.. its just guess work

no clue if it will work for you...Edit user/pass variable and let me know!

  Quote
Option Explicit

Dim objNetwork

Dim? strUser, strPassword, strUNCPrinter

' Values of variables set

strUNCPrinter = "\\server1\Lexmark"

strUser = "guytom"

strPassword = "?@ssw0rd1"

Set objNetwork = WScript.CreateObject("WScript.Network")

objNetwork.AddWindowsPrinterConnection strUNCPrinter, strUser, strPassword

WScript.Echo "Script finish, Check printer"

WScript.Quit

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Streaming was exciting and new in the beginning, nowadays all these services just s#ck big time. Sh#tty shows, cancellations even before a first season has aired, ads, more ads and ever increasing prices. Like I said in a previous post, invest some time setting up a local media server and be way happier. 😉
    • First thing that popped into my head reading this as well.....
    • Windows 11/10 package manager UniGetUI gets massive update with bulk download options by Usama Jawad UniGetUI (formerly WinGetUI) is a considerably popular Windows package manager. It basically combines command-line interfaces from package managers like Chocolatey, pip, npm, and more, in a single intuitive GUI. The project is available on GitHub under the MIT license, sporting almost 17,000 stars and 547 forks, and a decent amount of watchers. Today, UniGetUI has received version 3.3.0. It is interesting to note that this release was actually meant to be version 3.2.1, following on from a respectable 3.2.0 release back in May. But since it features a massive change log with more changes than originally planned, the developer decided to bump it up to version 3.3.0 directly. The highlights from the latest release include an option to bulk-download installers, select a package manager executable, default install options for each package manager, and cloud backup and restore functionalities. In addition, more commands are now supported, and users have the ability to kill processes before installing, uninstalling, or updating a package. There are lots of other capabilities in tow, too. PowerShell7 now clears older versions when updating, the Searchbox has been moved to improve space utilization, the toolbar has been enhanced, internal error detection mechanisms have been upgraded, and some dialog boxes have netted updates. There are tons of other backend changes too, including a note that XAML and YAML files cannot be created anymore due to low usage - the developer says that these formats are only used by 0.7-1.3% of all bundles, so it's difficult to maintain the development overhead required to manage them. As expected, there are lots of fixes contributed by the very active UniGetUI community, too. You can find out the full details in the massive change log here. You can download UniGetUI version 3.3.0 stable from the Neowin software stories page or from its official GitHub repo linked above.
    • Sounds useful. It isn't reading your messages and sending them to Google ffs.
  • Recent Achievements

    • One Month Later
      Ricky Chan earned a badge
      One Month Later
    • First Post
      leoniDAM earned a badge
      First Post
    • Reacting Well
      Ian_ earned a badge
      Reacting Well
    • One Month Later
      Ian_ earned a badge
      One Month Later
    • Dedicated
      MacDaddyAz earned a badge
      Dedicated
  • Popular Contributors

    1. 1
      +primortal
      504
    2. 2
      ATLien_0
      207
    3. 3
      Michael Scrip
      205
    4. 4
      Xenon
      141
    5. 5
      +FloatingFatMan
      116
  • Tell a friend

    Love Neowin? Tell a friend!