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)
}
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.