notification on logon
is there some way to trigger an acction on logon?
i would like to get a push notification when some one logs in to my machine (hoppefully just me)
i have tried to audit (windows biuld in) the Connections_incoming.txt and if there is write access trigger an acction with tasksheduler
problem is the login is writen on log OUT so some one could log in and do hawok for a day and when his job is done and he logs out i get a notification
this is from my point of view also a general falw if there is a power cut during this time there will be nothing loged to the file (i know there is the TeamViewer15_Logfile.log wich seems instant)
using the TeamViewer15_Logfile.log would mean i need some more serious logic because on a session there ara constant writes to it and i would get notifications every second during i am loged in so i would need to catch some parse in the file like "loged in" and react to that
i hoppe for a more straight forward solution
thx in advance cheers rick
Comments
-
here is a working version
$global:EOF = "`r`n"
$Path = "c:\Program Files (x86)\TeamViewer\"
$File = "TeamViewer15_Logfile.log"
$global:TeamLog = $Path + $File
$global:MyLog = $Path + "MyLog.txt"
$global:NumLines = (Get-Content $TeamLog | Measure-Object -Line).Lines
Write-Host "$TeamLog $MyLog"
Add-content $MyLog -value "Start"
$filewatcher = New-Object System.IO.FileSystemWatcher
$filewatcher.Path = $Path
$filewatcher.Filter = $File
$filewatcher.NotifyFilter = [IO.NotifyFilters]'Size'
$filewatcher.EnableRaisingEvents = $true
$writeaction = {
$NumLinesNew = (Get-Content $TeamLog | Measure-Object -Line).Lines
$NewLines = $NumLinesNew - $NumLines
$NewText = Get-Item -Path $TeamLog | Get-Content -Tail $NewLines
$HitTest = Select-String -InputObject $NewText -Pattern 'incoming session via' -AllMatches
$ChangeType = $Event.SourceEventArgs.ChangeType
$LogText = "$(Get-Date), $ChangeType NumLines:$NumLines -> $NumLinesNew($NewLines) HitTest:$($HitTest.Length)"
If ($HitTest.Length -gt 0){
$From = "at@at.at"
$To = "123456@pomail.net"
$Subject = "TeamViewer"
$Body = "LOGIN at MyComputer"
$SMTPServer = "123.123.123.123"
$SMTPPort = "25"
Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort
}
Write-Host $LogText
Add-content $MyLog -value $LogText
$NumLines = $NumLinesNew
}
Register-ObjectEvent $filewatcher "Created" -Action $writeaction
Register-ObjectEvent $filewatcher "Changed" -Action $writeaction
Register-ObjectEvent $filewatcher "Deleted" -Action $writeaction
Register-ObjectEvent $filewatcher "Renamed" -Action $writeaction
while ($true) {sleep 1}its the first time i done something with powershell
its also not cleaned up
nor the final version
but its working
0