running xp_cmdshell but cmd window opens on a different server

  •  I need to know if there is a way to run xp_cmdshell on my database server but opens up a command window on my fileserver to execute the a bat file on the file server? 

    I attempted to create a batch file on my file server (dir >testA.bat - saved as Test.bat) and called it from my database server (exec xp_cmdshell \\servername\c$\test.bat).  But it opens up a window on my Database server and puts the file there?  I know I could use a unc path for the batch file (dir >\\servername\c$\testA.bat) but the "test" is to open the command window from the file server. 

    Thanks in advance!

    JG

  • Are you looking to see an command prompt window on SQL Serve or on the Remote box ??? not possible.

    Are you looking to just initiate a batch file from a remote machine ??? possible.

    see PsExec at http://www.microsoft.com/technet/sysinternals/utilities/pstools.mspx


    -- Amit



    "There is no 'patch' for stupidity."



    Download the Updated SQL Server 2005 Books Online.

  • The command window will always "open" from the server... you can, however, run remote bat files... you just need to pass all file info as a UNC including the result of the DIR command.

    If you'd give a few more details about what the .bat file is supposed to do, you just never know... someone might actually be able to come up with a solution that'll make you happy.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • If you need to run the batch on regular base, you can run it from a scheduled task.

    Moreno

  • I came here to say what Amit said. So, seconded on the sysinternals tools. 

  • Thank you all for your replies.  I think I'm going to use the PSEXec utility.  I actually did some research and came across it, so it's funny that you mentioned it here. 

    The problem is that I can't run FTP from my database server but that is where I'm calling the .bat file.  So I need to run it on the database server but have it actually execute on the file server.  PSEXEC will actually execute from the server you specify.  Just as if you were on that server.  Pretty cool...

Viewing 6 posts - 1 through 5 (of 5 total)

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