"net share xyz /DELETE" fails if a file is in use on that share
The solution is to supply /Y to force the delete. This isn't documented, unfortunately.
Can't you just echo Y
? If it's not using cmd, then just run it with %COMSPEC% /c echo Y | net...
.