2

I am creating a script, to monitor user activity in the downloads folder. Ive decided to use FileSystemWatcher event to trigger and alert.

This script do the job, but only works when the instance of powershell is running, y dont want to have a powershell process running all the time.

There is a way to to persist this event subscription after the process is closed.

$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = "C:\"
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
Register-ObjectEvent $watcher "Created" -Action {
 [System.Windows.Forms.MessageBox]::Show($eventArgs.FullPath) 
}
kimo pryvt
  • 483
  • 1
  • 7
  • 25

1 Answers1

2

Marthias is right you can have a schedule task to keep powershell process always alive by adding.

on start a program PowerShell.exe and add arguments -noexit -noprofile

DisplayName
  • 1,008
  • 10
  • 24