Is it possible in Windows 10 to run a scheduled task only if a mapped network drive is not present?

Background: I have a task, a batch script, that maps two network drives for a backup service (CrashPlan). The batch script checks if the drive is present if exist Y:\ (...) and maps it otherwise net use Y: ....

This works, but since these network paths might not be present at system start or login (NAS switched off when I start my computer), I need to repeat this task regularly to ensure that the drives are mapped if/when the network paths become available.

But I really only need to repeat the task if the drive hasn't already been mapped, so I'd like to skip the task whenever the drives are aready present.

There's no harm in running the task anyway - it just skips the net use command, but the log would be cleaner if I could skip the task when it's not needed.

The underlying "problem" is to make sure the two mapped drives are always present to the CrashPlan service, running under the SYSTEM account, whenever the network paths are available (the NAS devices are online). Feel free to suggest completely different approaches to this, but perhaps try to keep those in comments, to avoid cluttering this question's answer. I'd be happy to post such a question separately if adviced to do so.


Add to your script command that disable this task on success somewhere around if exist Y:\ (...) and maps it otherwise net use Y: ...

schtasks.exe /CHANGE /TN "YourBatchScriptTask" /DISABLE

and add one more task that enable "YourBatchScriptTask" on computer start

schtasks.exe /CHANGE /TN "YourBatchScriptTask" /ENABLE

but if it would be me, I would keep this "checking" part since you can't guarantee that network connection to your NAS wouldn't be broken. (assume some kitten played with Ethernet cables)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.