Announcement

Collapse
No announcement yet.

Can HS3 stop/restart Windows services?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Can HS3 stop/restart Windows services?

    I've got some other windows services running on the same machine as HS3. Is there a script or something that'll allow me to stop/start/restart a windows service?

    I'd love to use HS3 via Alexa to handle restarting the service. Rather I'd love to have my wife/kid be able to stay "Alexa, turn on|off servicename". And have HS3 figure out if it needs to start or restart the 'servicename'. I'm not expecting this to be dynamic. I'd set up a device and/or events for this as a virtual device.

    Bonus would be allowing for windows credentials to allow controlling it remotely on another windows machine. At some point I may want to migrate the service onto another box.

    I did some searching here already, but as you can imagine searching on generic terms like windows and services doesn't exactly point to specific stuff.

    #2
    This may be a place to start
    https://rutg3r.com/control-a-windows...vb-net-script/
    Mike____________________________________________________________ __________________
    HS3 Pro Edition 3.0.0.548, NUC i3

    HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

    Comment


      #3
      Here is the function (hs.launch) that you would use to call the service. I think you would run net stop/start "Service Name" /y

      Launch
      Function Launch(ByVal Name As String, _
      ByVal Params As String, _
      ByVal Directory As String, _
      ByVal LaunchPri As Integer) As Integer

      Purpose
      Launches a given application. The function will return before the application finishes launching.

      Parameters
      Parameter: Name
      Type: String
      Description: This is the name of the EXE file to launch. It can be a simple application name (the path to the application would have to be in your system
      path) or it can be a full path name to the file. Application files can also be launched and the application that owns the file will be executed.

      Parameter: Params
      Type: String
      Description: Any parameters or command line switches that are to be passed to the application.

      Parameter: Directory
      Type: String
      Description: The working directory the application is launched from. Leave an empty string for most applications.

      Parameter: LaunchPri
      Type: Integer
      Description: The running priority of the process. Use -1 for Below Normal, 0 for Normal, 1 for Above Normal

      Returns
      Return value: Process Instance
      Type: Integer
      Description: The instance number of the process (not very useful).

      Comment


        #4
        I agree running net.exe is the easiest.

        Here is a script where you can see the results in the HS log:

        Code:
        Imports System.Diagnostics
        
        Sub Main(ByVal Parm As String)
        
        Dim myprocess As Process = New Process
        myprocess.StartInfo.FileName = "net.exe"
        myprocess.StartInfo.Arguments = Parm
        myprocess.StartInfo.UseShellExecute = False
        myprocess.StartInfo.CreateNoWindow = True
        myprocess.StartInfo.RedirectStandardInput = True
        myprocess.StartInfo.RedirectStandardOutput = True
        myprocess.StartInfo.RedirectStandardError = True
        myprocess.Start()
        hs.writelog("Result", myprocess.StandardOutput.ReadToEnd)
        
        End Sub
        Just send what you want through the script parameter such as "stop <service name>" or "start <service name>"

        Some services may ask for a confirmation when starting. In this instance use "start <service name> /Y"

        You can run this through my Alexa helper but you would have to say "Tell Homeseer....."
        Jon

        Comment


          #5
          I'm thinking a virtual device that Alexa sees as an on/off 'light' would be less tedious that having to use the Homeseer skill. Then just have HS events that track the device being changed, and call a stop/start accordingly.

          Though I wouldn't mind having it be a bit more robust than just using net stop|start.

          Comment


            #6
            Both Alexa skills have their advantages and disadvantages. Whilst Tell Homeseer can be tedious, it can at least provide you with proper responses such as confirmation of the service status from the output of net start/stop command.
            Jon

            Comment

            Working...
            X