Batch file - S: /DELETE

I use a cloud service that backs up all my data but it does not support networked drives.  

They provide a work around:

net use S: /DELETE
net use S: "\\<device_ip_address>\<share_name>" "<password>" /USER:"<username>" >>C:\tmp\mount.log

Open in new window

Looking at the  Net Use on TechNet - and I am thinking that this is going to want to create an S: drive, but to make sure that the S drive is not being used, it is deleted first?  

Just want to make sure I am understanding this before I use it

LVL 29
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It's correct, the /delete is not totally necessary, but just to make sure you start "clean" (less error prone if you do it this way).
Yes, that's what will happen; net use S: /delete does not actually delete anything, it just removes any other share mapped to this drive letter.
To avoid the error message that appears when no drive is mapped to S you can simply use
net use S: /DELETE >NUL 2>&1

Open in new window

Two additional notes, just in case:

* You might want to add a "/persistent:no" to the "net use"; otherwise Windows might prompt you for the password on each logon, because it will try to reconnect the drive - unless you want to be prompted, of course; then you should add "/persistent:yes":
net use S: /DELETE
net use S: "\\<device_ip_address>\<share_name>" "<password>" /USER:"<username>" /PERSISTENT:NO >>C:\tmp\mount.log

Open in new window

* If you don't feel like saving your password in the batch script, you can replace the "<Password>" with a single "*" (without quotes).
Here's a script that prompts you even with the log file activated; note that there will be no console echo, not even asterisks:
@echo off
set CloudShare=\\<device_ip_address>\<share_name>
net use S: /DELETE >NUL 2>&1
echo Type the password for '%CloudShare%':
net use S: "%CloudShare%" * /USER:"<username>" /PERSISTENT:NO >>C:\tmp\mount.log

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lee W, MVPTechnology and Business Process AdvisorCommented:
That COULD be a WASTE of time.  If it's works by drive letter, fine, but there are ways to enumerating local disks and a drive letter does not guaranteed it's viewed as local.  Your best option is a backup solution that works or installing this one on the system providing the "S" drive.
coreybryantAuthor Commented:
Thanks - Follow up question coming now...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.