0

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
Krish
  • 319
  • 4
  • 19

1 Answers1

1

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\"" 
MC ND
  • 69,615
  • 8
  • 84
  • 126
  • Hi @MC ND! Thank you for your answer but I'm trying this now, but I'm getting access is denied. do I have to be an Administrator of the machine I am accessing via wmic? – Krish Oct 07 '16 at 03:00
  • Hi @MC ND! I tried using an administrator account of the target machine to issue the wmic command and it works. However, my batch file actually writes a log to a text file but it doesn't write to a file when I run the batch file using wmic. It works fine though if I run the batch file locally on the target machine... – Krish Oct 07 '16 at 03:39
  • @Krish, for the access rights, you could read [here](https://social.technet.microsoft.com/Forums/office/en-US/4f33837b-1cb1-4648-85b1-3ba87cbfe93e/wmi-remote-access-denied?forum=winserverManagement) how to handle it and adapt to your needs. For the log file, remember you are executing it in the remote machine, with a different account and a different default active directory. – MC ND Oct 07 '16 at 05:56
  • Hi @MC ND! For the log file, I still can't get to have the batch file write to a file. I posted another post about it here [link] (http://stackoverflow.com/questions/40607634/which-account-is-used-when-executing-xp-cmdshell-wmic-java-jar). Can you take a look and give some insights? I really think the permission issue arises when I use wmic command. – Krish Nov 16 '16 at 03:47