XP_CMDSHELL to delete external files

  • I'm using this command:

    EXEC MASTER..XP_CMDSHELL 'del \\lpusback0002\mssql\lpusmvg0001\mvg\mvgdev061025120.trn'

    and I'm getting this error:

    \\lpusback0002\mssql\lpusmvg0001\mvg\MVGDEV061025120.trn

    Access is denied.

    NULL

    any ideas why?

    thanks in advance

  • Does the server have permission to delete that file?

  • Yes the server and the user has permission to delete the file

  • may be you should check your NT authentication login on that folder, which I have seen sometimes might cause such errors.

    Also were you able to access this file with the following command.

    EXEC MASTER..XP_CMDSHELL 'dir \\lpusback0002\mssql\lpusmvg0001\mvg\mvgdev061025120.trn'

    But beats me why you got a NULL which is usually a sign that it ran fine..

    Anyone feel free to correct me if I'm wrong.. I can learn too.

     

  • Well, I fix the problem temporarilly executing the NET USE command and map the drive and then executeint xp_cmdshell and after that NET USE again and Unmap the drive, works fine, but still very strange.

    But thanks anyway for your response.

  • I have had a LOT of problems (issues) with network drives.  The privilege associated with the command is of the user that starts the service - NOT the user who is logged on.  So, I know that much... I still have problems with it.

    My current problem is across domains.  There is a service account on both domains, a domain user with sysadmin; but the accounts do not appear to be "trusted" from one domain to the other.  I do not know what the password for the account is on the other domain... I once heard someone say that the passwords had to be the same; but I'm not sure... and I have no way of knowing - they won't tell me. (although they DO want the work to be done).

    Anyway, I'm rambling with no solution.  Hope you get an answer and post back here... it may help me resolve my issues.

    Good luck!

    Thank-you,
    David Russell
    Any Cloud, Any Database, Oracle since 1982

  • From Book online...

    "When xp_cmdshell is invoked by a user who is a member of the sysadmin fixed server role, xp_cmdshell will be executed under the security context in which the SQL Server service is running. When the user is not a member of the sysadmin group, xp_cmdshell will impersonate the SQL Server Agent proxy account, which is specified using xp_sqlagent_proxy_account. If the proxy account is not available, xp_cmdshell will fail. "

    Check and see if the Proxy account is set and if so what is it set to.  If you are calling the xp_cmdshell command from a non Sysadmin account, you'll need to allow the proxy account user share and ntfs access to the files you are trying to delete.  You'll need to set the share as full control, and modify permissions on the NTFS permissions on that folder and it's subfolders. 

     

    To help us help you read this[/url]For better help with performance problems please read this[/url]

  • Map network address as a local hard drive, and give new file name string.

  • yeah, that sounds so simple... it was tried about two weeks ago.  thanks for the idea; but it was not the solution.  Our IT people have been working on other issues... and I bill to their charge numbers, so I am sure that they will fix it when they can.  It would be nice to tell them how... and the post one up from yours quoting BOL might be worth re-reading...maybe the proxy account is not there... not sure at the moment.

    Serious, thank you all for your comments...

    Thank-you,
    David Russell
    Any Cloud, Any Database, Oracle since 1982

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply