Search code examples
windowsbatch-fileubuntusambasmb

Batch script map samba share with username and password and auto dismount


I'm trying to add a Samba share on Ubuntu to a mapped drive on Windows, from a batch script. I need to specify the username and password in the batch file to access the share. I know this is bad security, but I need it like this because the batch script will be automatically generated from something else. The share should also be unmounted after 30 minutes.


Solution

  • Have a look at net use /help, which explains how to map a share, and how to delete it.

    For the "30 minutes" part, i'd use schtasks to create a scheduled task to run at the specified time. If you want to stay self-contained, more modern versions of windows (7ff, i believe) support TIMEOUT /T 1800 /NOBREAK, which waits 1800 seconds and ignores keypresses.