Login.bat updates and adding networked printers

Posted on 2006-04-05
Last Modified: 2010-03-19
Hey All,

The IT guru before me created a login.bat script to automatically map network drives. One of the drives is no longer applicable, and I was curious on how to update that script to do the following:

- Include mapping to network printers
- remove that mapped drive
- map to personal drive for that user for files saved on the network

From looking at the file in Notebook, removing the network drive seems to be as easy and deleting it, but what about the others?

Please help.

Question by:pstiffsae
    LVL 8

    Accepted Solution

    Most mapping is done using the NET USE command.

    Net use Connects a computer to or disconnects a computer from a shared resource, or displays information about computer connections. The command also controls persistent net connections. Used without parameters, net use retrieves a list of network connections.

    net use [{DeviceName | *}] [\\ComputerName\ShareName[\volume]] [{Password | *}]] [/user:[DomainName\]UserName] [/user:[DottedDomainName\]UserName] [/user: [UserName@DottedDomainName] [/savecred] [/smartcard] [{/delete | /persistent:{yes | no}}]

    net use [DeviceName [/home[{Password | *}] [/delete:{yes | no}]]

    net use [/persistent:{yes | no}]

    Assigns a name to connect to the resource or specifies the device to be disconnected. There are two kinds of device names: disk drives (that is, D: through Z:) and printers (that is, LPT1: through LPT3:). Type an asterisk (*) instead of a specific device name to assign the next available device name.
    Specifies the name of the server and the shared resource. If ComputerName contains spaces, use quotation marks around the entire computer name from the double backslash (\\) to the end of the computer name (for example, "\\Computer Name\Share Name"). The computer name can be from 1 to 15 characters long.
    Specifies a NetWare volume on the server. You must have Client Service for NetWare installed and running to connect to NetWare servers.
    Specifies the password needed to access the shared resource. Type an asterisk (*) to produce a prompt for the password. The password is not displayed when you type it at the password prompt.
    Specifies a different user name with which the connection is made.
    Specifies another domain. If you omit DomainName, net use uses the current logged on domain.
    Specifies the user name with which to log on.
    Specifies the fully-qualified domain name for the domain where the user account exists.
    Stores the provided credentials for reuse.
    Specifies the network connection is to use the credentials on a smart card. If multiple smart cards are available, you are asked to specify the credential.
    Cancels the specified network connection. If you specify the connection with an asterisk (*), all network connections are canceled.
    /persistent:{yes | no}
    Controls the use of persistent network connections. The default is the setting used last. Deviceless connections are not persistent. Yes saves all connections as they are made, and restores them at next logon. No does not save the connection being made or subsequent connections. Existing connections are restored at the next logon. Use /delete to remove persistent connections.
    Connects a user to the home directory.
    net help command
    Displays help for the specified net command.
    Connecting and disconnecting from a network resource
    Use net use to connect to and disconnect from a network resource, and to view your current connections to network resources. You cannot disconnect from a shared directory if you use it as your current drive or an active process is using it.

    Viewing connection information
    To view information about a connection, you can do either of the following:

    Type net use DeviceName to get information about a specific connection.
    Type net use to get a list of all the computer's connections.
    Using deviceless connections
    Deviceless connections are not persistent.

    Connecting to NetWare servers
    After you install and run Client Service for NetWare, you can connect to a NetWare server on a Novell network. Use the same syntax that you use to connect to a Windows Networking server, except you must include the volume you to which you want to connect.

    Using quotation marks
    If the ServerName that you supply contains spaces, use quotation marks around the text (that is, "Server Name"). If you omit quotation marks, an error message appears.

    To assign the disk-drive device name E: to the Letters shared directory on the \\Financial server, type:

    net use e: \\financial\letters

    To assign (map) the disk-drive device name M: to the directory Mike within the Letters volume on the \\Financial NetWare server, type:

    net use m: \\financial\letters\mike

    To connect the user identifier Dan as if the connection were made from the Accounts domain, type:

    net use d:\\server\share /user:Accounts\Dan

    To disconnect from the \\Financial\Public directory, type:

    net use f: \\financial\public /delete

    To connect to the resource memos shared on the \\Financial 2 server, type:

    net use k: "\\financial 2" \memos

    To restore the current connections at each logon, regardless of future changes, type:

    net use /persistent:yes


    Author Comment

    So is it possible to map a networked printer/copier machine? It exists on it's own IP address but I'm unsure about the device name.
    LVL 8

    Expert Comment

    It depends on the printer  - if the printer supports microsoft networking and sharenames.  I generally use a "print server" to share printers on the network.

    What make model are you looking to work with.
    LVL 2

    Expert Comment

    by:Brian Lowrance
    - Removing a drive mapping in a .BAT logon script:
        Just delete the line NET USE driveletter: \\servername\non_existent_sharename

    - Mapping drives on login to the users personal folder:
        I assume you will have several users that are set to run this logon script.
        To map personal drives that are on a server or another workstation add to your logon script .bat file:
        NET USE H: \\servername\%username%
        Note: Change servername to the servers name where your users personal drives are shared.  Leave %username% as it is, this is a variable that will automatically be filled in with the users logon name , so if jdoe logs in, the command will actually read \\servername\jdoe

    Author Comment

    they are Ricoh 2075's. They are installed on one of our servers and we simply go to the shared printer and install it. Should I do something else?
    LVL 8

    Expert Comment

    No you should be able to just user the \\servername\sharenameofprinter.

    Author Comment

    This is a dumb quesiton, but how do I determine the name of the printer... we have it as Ricoh 2075 Finance
    LVL 8

    Expert Comment

    Logon to the server, go to the printer folder (under control panel)
    right mouse on the printer you wish to find out about
    Then select "Sharing" - the name is listed

    Author Comment

    it's listed with spaces, should it not?
    LVL 8

    Expert Comment

    It's not recommend to use spaces in a share name.  If you change it you will also have to change it on any computer that its currently being used by.

    Author Comment

    can I still change the login.bat and keep the share with spaces or no, and what would I put in there in the code?
    LVL 8

    Expert Comment

    No the share name has to match

    The following command will allow you to use the share name with spaces.  Also pick a LPTX number such as LPT4: (something that isn't currently being used)

    NET USE [LPTx:] "\\ComputerName\printer_share"
    LVL 8

    Expert Comment


    Have you had any luck with mapping to the printers?  Can we help with anything?

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Data center, now-a-days, is referred as the home of all the advanced technologies. In-fact, most of the businesses are now establishing their entire organizational structure around the IT capabilities.
    ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
    After creating this article (, I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    728 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

    18 Experts available now in Live!

    Get 1:1 Help Now