Saturday, April 14, 2012

Mounting CIFS shares from Windows command line

Unfortunately, sometimes even Linux geeks have to do it...

If you need to mount or unmount ('map' or 'disconnect' in Windows lingo) a Windows (Samba) share from Windows command line or batch file, you can do it with 'net use' command.

To map a network drive:
  1. Click Start, and then click Run (or use Windows+R keyboard shortcut).
  2. In the Open box, type cmd to open command line window.
  3. Type the following, replacing X: with drive letter you want to assign to the shared resource:
    net use X: \\computer_name\share_name
To disconnect a mapped drive:
  1. Open command line window.
  2. Type the following, replacing X: with drive letter of the shared resource:
    net use  X: /delete