• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
TRIGGERcmd
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

reverse Trigger Cmd

General Discussion
3
5
283
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F
    F4u5t
    last edited by Feb 4, 2020, 9:53 PM

    I have finally found trigger cmd and love it, now I want to got the other way, have actions on my computer ( file write, application open...) cause a trigger on IFTTT or Alexa...
    anyone know how

    1 Reply Last reply Reply Quote 0
    • F
      F4u5t
      last edited by Feb 6, 2020, 2:03 PM

      I think i can basically accomplish what I want with sendresult.bat

      R 1 Reply Last reply Feb 6, 2020, 4:48 PM Reply Quote 0
      • R
        Russ @F4u5t
        last edited by Russ Feb 6, 2020, 6:50 PM Feb 6, 2020, 4:48 PM

        @F4u5t, the sendresult.bat script is meant for sending a small bit of data that your command produces back to the server. I don't think that matches your original post's use case.

        Here's a Powershell script you could use to watch for new processes, and call an API when one of the processes you're looking for launches. I had it call the TRIGGERcmd API, but you could easily switch it to the IFTTT Webhooks API.

        Let me know if you want a file write example too.

        # Define event Query
        # $query = "SELECT * FROM __InstanceCreationEvent WHERE TargetInstance ISA 'Win32_NTLogEvent' "
        $query = "SELECT * FROM Win32_ProcessStartTrace"
        
        <# Register for event - also specify an action that displays the event when the event fires.#>
        Register-WmiEvent -Source Demo1 -Query $query -Action {
                $processes = "mspaint.exe","calculator.exe"
        
                # Use this if reading Win32_NTLogEvent's:
                #  $event.SourceEventArgs.NewEvent.TargetInstance.Message
                $p = $event.SourceEventArgs.NewEvent.Properties["ProcessName"].value
        
                foreach ($process in $processes) {
                    if ($p -eq $process) {
                        Write-Host "$p launched.  Calling API."
                        
                        $postdata = @{
                            trigger='notepad'
                            computer='RussHP'
                            # params='optionalparameter.txt'
                        }
                        
                        $token=Get-Content ~\.TRIGGERcmdData\token.tkn
                        
                        $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
                        $headers.Add("authorization", "Bearer " + $token)
                        
                        $json = $postdata | ConvertTo-Json
                        $response = Invoke-RestMethod 'https://www.triggercmd.com/api/run/triggerSave' -Method Post -Body $json -ContentType 'application/json' -Headers $headers
                        write-host $response
                    }
                }
            }
        
        "Waiting for events.  Press CTRL-C to quit."
        while($true)
        {
            Start-Sleep .5
        }
        

        The script I based this one on watched for entries in Event Viewer. I left those bits remarked out in case you might have that use case.

        Russell VanderMey

        1 Reply Last reply Reply Quote 0
        • F
          F4u5t
          last edited by Feb 6, 2020, 5:55 PM

          that is fantastic, Thank you! I've been learning much since stumbling on Triggercmd...I would love a example of a file write, and IFTTT would be sweet also.
          To be honest, ive never done much with Powershell, and its been years since i wrote batch files, I'm mainly c# nowadays

          R 1 Reply Last reply Feb 6, 2020, 6:54 PM Reply Quote 0
          • R
            Russ @F4u5t
            last edited by Russ Feb 6, 2020, 6:55 PM Feb 6, 2020, 6:54 PM

            @F4u5t, here's an example to watch a folder for new files, and call the IFTTT webhook.

            $watcher = New-Object System.IO.FileSystemWatcher
            $watcher.Path = 'D:\folder_to_watch'
            $watcher.IncludeSubdirectories = $true
            $watcher.EnableRaisingEvents = $true
            
            $action =
            {
                $path = $event.SourceEventArgs.FullPath
                $changetype = $event.SourceEventArgs.ChangeType
                Write-Host "$path was $changetype at $(get-date)"
            
                $postdata = @{
                    value1=$path
                    value2=$changetype
                }
                
                # To get your key, click the Documentation link at https://ifttt.com/maker_webhooks/
                $key="your_ifttt_key"
                $event="new_file"
                
                $json = $postdata | ConvertTo-Json
                $response = Invoke-RestMethod "https://maker.ifttt.com/trigger/$event/with/key/$key" -Method Post -Body $json -ContentType 'application/json'
                write-host $response
            
            }
            
            Register-ObjectEvent $watcher 'Created' -Action $action
            
            "Waiting for events.  Press CTRL-C to quit."
            while($true)
            {
                Start-Sleep .5
            }
            

            Russell VanderMey

            1 Reply Last reply Reply Quote 0
            3 out of 5
            • First post
              3/5
              Last post