{"id":110823,"date":"2017-06-09T09:00:45","date_gmt":"2017-06-09T16:00:45","guid":{"rendered":"https:\/\/www.microsoft.com\/en-us\/power-platform\/blog\/power-automate\/flow-of-the-week-local-code-execution\/"},"modified":"2017-06-09T09:00:45","modified_gmt":"2017-06-09T16:00:45","slug":"flow-of-the-week-local-code-execution","status":"publish","type":"power-automate","link":"https:\/\/www.microsoft.com\/en-us\/power-platform\/blog\/power-automate\/flow-of-the-week-local-code-execution\/","title":{"rendered":"Flow of the Week: Local code execution"},"content":{"rendered":"
This Flow of the Week was\u00a0written by Ashwin Sathya Raghunathan. Thanks for contributing!<\/em><\/p>\n ———————————<\/em><\/p>\n Today,\u00a0I want to talk about something that opens up the flow beyond the scope of connecting cloud services and being able to help running tasks on your local computer. Very often I forget to lock my computer before leaving the desk only to remember it later in a meeting, but by this time the damage would already be done, such as a\u00a0prank e-mail to the team from my mailbox. So, we are going to attempt a solution to this problem using the following capabilities:<\/p>\n Gateways provide a way for on-premise services to connect to the cloud. Use cases involve connecting a on-premise SQL database to a flow for use in internal systems where customers don\u2019t want their SQL data in the cloud.<\/p>\n In addition, flow buttons are an elegant way to trigger a flow with a single click. (We could also integrate a hardware button from home that could do the same with a HTTP request.)<\/p>\n With the above said, the solution involves the following:<\/p>\n A PowerShell script that is running in your local computer.<\/strong> The script is watching a directory for a file event and locks the computer on it:\n
\nApproach<\/h2>\n
\n\u00a0<\/p>\n\n$watcher = New-Object System.IO.FileSystemWatcher\n\n$watcher.Path = \"C:\\Lock\"\n\n$watcher.Filter = \"*.*\"\n\n$watcher.IncludeSubdirectories = $true\n\n$watcher.EnableRaisingEvents = $true\u00a0\n\n$action = {\n\n\u00a0\u00a0\u00a0 . rundll32.exe user32.dll,LockWorkStation\n\n}\u00a0\u00a0\u00a0\n\n### DECIDE WHICH EVENTS SHOULD BE WATCHED\n\nRegister-ObjectEvent $watcher \"Created\" -Action $action\n\nRegister-ObjectEvent $watcher \"Changed\" -Action $action\n\nRegister-ObjectEvent $watcher \"Deleted\" -Action $action\n\nRegister-ObjectEvent $watcher \"Renamed\" -Action $action\n\nwhile ($true) {sleep 5}\n\n<\/pre>\n