Search code examples
sql-serverwindowscmdtelnetpsexec

issue a terminal command from an sqlserver to a windows machine


I have an sqlserver, say serverA, and a windows machine, say machineA.

I have a testrun.bat file in machineA that I need to run after a certain process is finished in serverA.

I have learned that I can use PSExec to issue a terminal command from serverA to machineA.

I'm just wondering if I can do this using Microsoft Telnet service? Because I am not sure if PSExec wiil be allowed to be installed in serverA because of certain security concerns.

Basically, I'm just looking for plan B in case I cannot use PSExec. Another way I realized that I can use is Microsoft telnet but I am not sure how or if it is even possible.

Additional details:

  • serverA runs Windows Server 2012
  • machine A runs Windows 7 Enterprise

Solution

  • Just use native wmic command.

    wmic /user:<username> /password:<password> /node:<machine> process call create "cmd /c c:\somewhere\myBatchFile.cmd"
    

    Remember that

    • As the process is created in the remote machine, the batch file must exist on it and the path has to reflect the location in the remote machine

    • The process is started under the indicated user, probably in a separate session. You will probably not see the batch file running, check the processes list

    • If the path to the batch file include spaces, you will need to quote it as

     wmic ... call create "cmd /c \"c:\some where\My Batch.cmd\""