Jump to content

Has anyone written a network resource that can shutdown a Windows PC on a local network?


Broyd

Recommended Posts

The network resource WOL works perfectly ... but I was wondering if anyone had cobbled together an ISY network resource plus something running on a local Windows PC that could initiate a Windows shutdown?

TIA for any suggestions! Broyd.

  • Like 1
Link to comment
  • 2 weeks later...

Initially I was looking for a method to shutdown a Windows PC
by sending a 'something' to the PC using a network resource.

This involved setting up a task on the Windows PC that could listen
on a port and respond to a shutdown command set from the ISY.
This task would have to be loaded when the PC was booted.  

When I had a closer look at this, I realized that I also wanted
a task that would play an alarm after the PC was fully booted up.

So in the end, I set up 3 python scripts to accomplish this;
I am including them here in the event that someone else might find
them useful.

The first python script's purpose is to start the two other scripts
independently and asynchronously. That is these two scripts run
as if they were started one at a time with no dependencies
associated between either script. They run and terminate
independently of each other.


So ... here are the three python scripts


# First, RunProcesses.py

import os                                                                       
from multiprocessing import Pool
from time import sleep
                                                                                
processes = ('C:\PythonScripts\PIII-10G-ShutDown.py', 'C:\PythonScripts\Pythonplaysound.py')                                     
                                                                                
def run_process(process):
    print('\nRunning process: ' + process)
    os.system('python {}'.format(process))                                       
                                                                                
def main() :
    pool = Pool(processes=2)
    pool.map_async(run_process, processes)

if __name__ == '__main__':
    print('Starting  MAIN')
    main()
    print('Finishing MAIN')
    sleep(2)
     
---=== End of Script ===---
 
# Second, PIII-10G-ShutDown.py

# I give credit to larryllix for the core of this script; I grabbed it from the forum many moons ago.

import os
import sys
import time
import datetime
from http.server import BaseHTTPRequestHandler, HTTPServer

# HTTPRequestHandler class (HTTP requests, either from a browser or the ISY994i are handled using this class.

class myHTTPServer_RequestHandler(BaseHTTPRequestHandler):
    
    def do_GET(self):
        self.send_response_only(200)
        words = self.requestline.split()
        params = words[1].split("/",2)
        
        #debug stuff
        #print("\n\nNumber of parmameters in input string:", str(len(params)))
        #print("\nInput string passed into Python:", words)
        #print("\nParameters received: ", params)
        
        Arg1 = params[1]
        
        if Arg1 == "Shutdown" :
           print("\nShutdown received.")
           os.system('"C:\ShutDown.bat"')

        elif Arg1 == "StartXYZ" :
           print("\nStarting Program XYZ.")
           os.system('"C:\XYZ.bat"')

        else :
           print("\nUnanticipated command received: " + str(Arg1))        
 
# Server settings

def run():
    #print('\nStarting server...')
    server_address = ('192.168.1.4', 10738)
    httpd = HTTPServer(server_address, myHTTPServer_RequestHandler)
    print('\n' * 2)
    print('Running server...')
    print('\n' * 2)
    httpd.serve_forever()
    
run()    

 ---=== End of Script ===---

~~~~~~~~~
A quick note on the shutdown script above. I set up and used English words in my
Network Resource PATH item. You could use variable substitution (numbers)
instead which allow any number of functions (for the python script) to use
one Network Resource.
~~~~~~~~~   
 
# Third, Pythonplaysound.py

from time import sleep
from playsound import playsound
print('\nBig Ben initiated.')
sleep(210)

# Note:- use of the FORWARD slash in the filename for playsound

playsound('C:/PythonScripts/BigBenClockCV3.mp3')

# print('\nBig Ben completed.')

 ---=== End of Script ===---
 
 
 
And finally, the ISY network resource:

Protocol Information:

http GET   Host: 192.168.1.4   Port: 10,738  Path: /Shutdown  Timeout: 500

  • Like 2
Link to comment
Guest
This topic is now closed to further replies.

×
×
  • Create New...