Re: XP_CMDSHELL

  • Hi,

    I would like to know how to run a batch file on a remote W2K/NT box by using xp_cmdshell. Here is how I did:

    1. Assign MSSQL service a domain account with local admin rights on both boxes.

    2. In SQL Query Analyzer, run

    use master

    exec xp_cmdshell '\\testserver\c$\test.bat'

    However,I always get an error message " The system cannot find the path specified".

    Can someone tell me waht's wrong?

    Thanks a lot!

  • you need double quotes due to the $ in the share name

    exec xp_cmdshell '"\\testserver\c$\test.bat"'

    give that a try.

    Wes

  • I have created c:\test.bat with the following content on Server01 :

     dir c:\ 

    From Server02 in QA, I executed the following:

     
    
    xp_cmdshell'\\SERVER01\c$\TEST.BAT'

    This had returned the contents of c:\ on SERVER02. May be we need to reference Server name inside your .BAT file as well.

    Can you paste the contents of your TEST.BAT file?!

    .

  • Wes,

    You don't need double quotes. It worked just fine with single.

    .

Viewing 4 posts - 1 through 3 (of 3 total)

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