How to map network drive with password in command line – WinXP / Win7 / Win8 ?

windowRecently i wrote a batch script for WinXP / Win 7 to map a network drive with password in command line to perform some files backup. Before this, I’ve been doing the backup for few WinXP and Win7 machines manually and it’s time consuming! Until i wrote my script, i automate this backup process using a batch script. As the most challenging part in writing this script is to connect a network drive with command line. So i decided to share this with everyone especially technical support staff here.

To map network drive with password in command line under WinXP / Win7 / Win8, try the code below:-


  • Let assume you are going to map this network drive to drive X:, so before doing any mapping you need to make sure drive X: is not being used. So we use the command below to remove drive X: (there might be error message showing the resource is not available, but it’s ok since we need to make sure the drive letter is not being used.)
     net use x: /delete /yes
  • Once the drive is removed, now we use the command below to map the network drive that we need.
     net use x: \\\publicshare /USER:SHAREPCNAME\myusername mypassword

    – the network drive located at with a share folder name “publicshare”
    – the network drive machine name is “SHAREPCNAME”
    – to connect the network drive you need login with “myusername” and “mypassword”

  • If you have everything correct, you should see a network drive X: being mapped and show at your “My Computer”

Happy Networking 🙂

Share this with your friends:-

Leave a Reply