views:

45

answers:

2

I am using below sql statement to create shared folder with permission
EXEC xp_cmdshell 'net share BackupSharedFolder=D:\testshared /REMARK:"test shared"'

It is working fine with create shed folder.

then i will use below sql command to remove shared EXEC xp_cmdshell ' net share BackupSharedFolder /delete"'

Above is also working fine if shared folder is not opened.

if shared folder is opened.It giving error like following "Users have open files on BackupSharedFolder. Continuing the operation will force the files closed. Do you want to continue this operation? (Y/N) [N]: No valid response was provided."

and ask for prompt for Yes or NO.

So, how can i force sql command to yes and remove share by this XEC xp_cmdshell ' net share BackupSharedFolder /delete".

A: 

So, I am bending the SO rules a little: instead of answering your question, I have to advise that doing this seems like a really bad idea. Please don't control the OS through SQL Server's xp_cmdshell. It's just wrong on so many levels... architecture, security, design ...

onupdatecascade
but i need to use xp_cmdshell in script to move db backup t anlother folder.
Paresh
If you are moving backup files around, have you looked at the SQL Server Agent task type for Operating System Command? I don't know if that would meet your needs, but it's safer than callng xp_cmdshell from T-SQL scripts.
onupdatecascade
A: 

I did not get any acceptable answer. i will do myself.

Paresh