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

  • Is PSExec something like what you are looking for?

  • Actually yes!!  In my research I came across that and it works perfectly.  Thanks!

  • If you're going to do much of this remote stuff, I'd recommend looking into all of the PSTools.

  • If you use PSExec, be aware that it requires that the caller (on server A) be a member of the local Administrators group on the targer (server B).  Before building an infrastructure using PSExec, it may be wise to check with your Security people if they will allow this to run in Production.

    There are other packages available that perform similar functionality which have components permanently installed on calling and target servers, but which do not need local Admin rights for execution.  Google will help you find these.  You could also ask your Windows Infrastructure people if they have anything already in-house that you can exploit.

    Original author: https://github.com/SQL-FineBuild/Common/wiki/ 1-click install and best practice configuration of SQL Server 2019, 2017 2016, 2014, 2012, 2008 R2, 2008 and 2005.

    When I give food to the poor they call me a saint. When I ask why they are poor they call me a communist - Archbishop Hélder Câmara

  • Yes we do have an local admin account that is on admins on both machines.  Thanks EdVassie!

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

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