Rechercher dans ce blog

vendredi 10 février 2023

Alarme évènements sur un écran - Mode télé travail

Update 10/02/2023

--------------------------------------------------


$i = 0

$PathPicture = "C:\..........\..........\imagesscreen"

New-Item $PathPicture -ItemType Directory -ErrorAction SilentlyContinue


Remove-Item "$($PathPicture)\*.*" -Force -Recurse


sleep -Seconds 5


do {

    sleep -Seconds 1

    $i++

    $File = "$($PathPicture)\Image$($i).bmp"


    Add-Type -AssemblyName System.Windows.Forms

    Add-type -AssemblyName System.Drawing



    $Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen

    $Width = [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Width

    $Height = [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Height


    $Left = 0

    $Top = 0


    ($bitmap = New-Object System.Drawing.Bitmap $Width, ($Height-40))  | Out-Null

    ($graphic = [System.Drawing.Graphics]::FromImage($bitmap)) | Out-Null


    ($graphic.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size))  | Out-Null

    $bitmap.Save($File) | Out-Null


    $CountPicture = (Get-ChildItem "$($PathPicture)\Image*.*").Count


    If($CountPicture -ge 2)

    {

        $Picture1 = Get-ChildItem "$($PathPicture)\Image$($i).bmp"

        $Picture2 = Get-ChildItem "$($PathPicture)\Image$($i-1).bmp"

    }

    else

    {

        Continue

    }

    $f1 = Get-FileHash -Path $Picture1
    $f2 = Get-FileHash -Path $Picture2


    Write-Host "$($Picture2.Name) : $($f2.Hash)"
    Write-Host "$($Picture1.Name) : $($f1.Hash)"


    if($f1.Hash -ne $f2.Hash)
   {

        Write-Host "PlaySound" -ForegroundColor Yellow

        $PlayWav = New-Object System.Media.SoundPlayer

        $PlayWav.SoundLocation = "C:\Windows\Media\Alarm01.wav"

        $PlayWav.playsync()


        #& "C:\Program Files\VideoLAN\VLC\vlc.exe" --play-and-exit '"C:\Windows\Media\Alarm01.wav"'


        sleep -Seconds 10


        # (New-Object Media.SoundPlayer 'C:\Windows\Media\Afternoon\Windows Notify.wav').Play();

    }


    Remove-Item $Picture2 -Force 

} while (

    $true

)