Skip to main content

Worklet: open website on end user's computer


Nic-Automox

I wrote this worklet at the request of one of our customers. They want to pop open a browser window to a survey site every morning for their users. To edit this for your use case, all you need to do is replace the URL in the $command variable, and to make sure that Powershell is allowed to run scripts on the endpoint as a user. This is because it’s making use of the scheduled task feature to run the worklet as the logged in user instead of System. To do that, you can run this command (as admin) on the endpoint:

`Set-ExecutionPolicy RemoteSigned’


Evaluation code:


Exit 1


Remediation code:


$time = (Get-Date).AddSeconds(5)

$triggerAt = New-ScheduledTaskTrigger -At $time -Once

$currentusr = (Get-WmiObject -class win32_process -ComputerName 'localhost' | Where-Object name -Match explorer).getowner().user

$command = "start https://www.google.com"



New-Item -Path "c:\ProgramData\Amagent" -Name "message.ps1" -ItemType "file" -Value $command



$action = New-ScheduledTaskAction -Execute Powershell.exe -Argument "-windowstyle hidden c:\ProgramData\Amagent\message.ps1"



Register-ScheduledTask -TaskName "StartMsg" -Trigger $triggerAt -Action $action -User $currentusr

Start-Sleep 6

Unregister-ScheduledTask -TaskName "StartMsg" -Confirm:$false

Remove-Item -Path "c:\ProgramData\Amagent\message.ps1"

0 replies

Be the first to reply!

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings