reverse Trigger Cmd
-
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 -
I think i can basically accomplish what I want with sendresult.bat
-
@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.
-
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 -
@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 }
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login