27 lines
737 B
PowerShell
27 lines
737 B
PowerShell
# get_idle_minutes.ps1
|
|||
|
|
Add-Type @"
|
||
|
|
using System;
|
||
|
|
using System.Runtime.InteropServices;
|
||
|
|
|
||
|
|
public class User32 {
|
||
|
|
[StructLayout(LayoutKind.Sequential)]
|
||
|
|
public struct LASTINPUTINFO {
|
||
|
|
public uint cbSize;
|
||
|
|
public uint dwTime;
|
||
|
|
}
|
||
|
|
|
||
|
|
[DllImport("user32.dll")]
|
||
|
|
public static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
|
||
|
|
}
|
||
|
|
"@
|
||
|
|
|
||
|
|
$lii = New-Object User32+LASTINPUTINFO
|
||
|
|
$lii.cbSize = [System.Runtime.InteropServices.Marshal]::SizeOf($lii)
|
||
|
|
[User32]::GetLastInputInfo([ref]$lii)
|
||
|
|
|
||
|
|
$tickCount = [Environment]::TickCount
|
||
|
|
$idleTicks = $tickCount - $lii.dwTime
|
||
|
|
if ($idleTicks -lt 0) { $idleTicks += 0x100000000 }
|
||
|
|
|
||
|
|
$idleMinutes = [Math]::Floor($idleTicks / 1000 / 60)
|
||
|
|
Write-Output $idleMinutes
|