Home:ALL Converter>Shutdown Remote Windows Machine

Shutdown Remote Windows Machine

Ask Time:2015-09-06T08:18:19         Author:ent.prog

Json Formatter

I'm looking for a way to remotely shutdown a Windows 7 or 8 machine with Lua. I can successfully use Telnet via the terminal in OS X or cmd prompt in Windows so I know the telnet server on the remote machine is working, login credentials work, and my command is correct.

Perhaps I'm going down the wrong path with trying to send the login info like this but here's what I have been tinkering with:

local socket = require("socket")
conn = socket.tcp() 
conn:connect("10.0.1.15",23) -- the remote machine I want to shutdown
socket.sleep(3)
conn:send("GrandMA2 onPC\r\n") -- the user name
socket.sleep(3)
conn:send("password\r\n") -- the password
socket.sleep(3)
conn:send("shutdown -r -f\r\n") -- the shutdown/restart command
socket.sleep(3)

I've tried various combinations of sleep times, \r, \n and so on. When using Wireshark to monitor Telnet connection I can clearly see that I'm not getting the responses I'd expect from the telnet server (like I would when using the cmd prompt or terminal).

Any help would be much appreciated.

Author:ent.prog,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/32418851/shutdown-remote-windows-machine
yy