-
Notifications
You must be signed in to change notification settings - Fork 10
/
GetIdleTime.ps1
57 lines (54 loc) · 1.57 KB
/
GetIdleTime.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function GetIdleTime
{
<#
.SYNOPSIS
Quote from http://www.pstips.net/detec-idle-time.html
#>
Add-Type @'
using System;
using System.Runtime.InteropServices;
namespace Win32_API
{
internal struct LASTINPUTINFO
{
public uint cbSize;
public uint dwTime;
}
/// <summary>
/// Summary description for Win32.
/// </summary>
public class Win32
{
[DllImport("User32.dll")]
public static extern bool LockWorkStation();
[DllImport("User32.dll")]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
[DllImport("Kernel32.dll")]
private static extern uint GetLastError();
public static uint GetIdleTime()
{
LASTINPUTINFO lastInPut = new LASTINPUTINFO();
lastInPut.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(lastInPut);
GetLastInputInfo(ref lastInPut);
return ( (uint)Environment.TickCount - lastInPut.dwTime);
}
public static long GetTickCount()
{
return Environment.TickCount;
}
public static long GetLastInputTime()
{
LASTINPUTINFO lastInPut = new LASTINPUTINFO();
lastInPut.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(lastInPut);
if (!GetLastInputInfo(ref lastInPut))
{
throw new Exception(GetLastError().ToString());
}
return lastInPut.dwTime;
}
}
}
'@
[Win32_API.Win32]::GetIdleTime()/1000
}
GetIdleTime