#Shutdown displays after 5 seconds
#Save as hiddenScreenSaver.ps1 and put the script in C:\Temp
Add-Type @'
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace PInvoke.Win32 {
public static class UserInput {
[DllImport("user32.dll", SetLastError=false)]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
[StructLayout(LayoutKind.Sequential)]
private struct LASTINPUTINFO {
public uint cbSize;
public int dwTime;
}
public static DateTime LastInput {
get {
DateTime bootTime = DateTime.UtcNow.AddMilliseconds(-Environment.TickCount);
DateTime lastInput = bootTime.AddMilliseconds(LastInputTicks);
return lastInput;
}
}
public static TimeSpan IdleTime {
get {
return DateTime.UtcNow.Subtract(LastInput);
}
}
public static int LastInputTicks {
get {
LASTINPUTINFO lii = new LASTINPUTINFO();
lii.cbSize = (uint)Marshal.SizeOf(typeof(LASTINPUTINFO));
GetLastInputInfo(ref lii);
return lii.dwTime;
}
}
}
}
'@
$boolCheck = $false
while($true)
{
if([PInvoke.Win32.UserInput]::IdleTime -gt '00:00:05.0000000')
{
if(-Not $boolCheck)
{
& 'C:\WINDOWS\system32\scrnsave.scr' @('/s')
Start-Sleep -Seconds 1
$boolCheck = $true
}
}
else
{
$boolCheck = $false
}
}
Comments
0 B
|👍
/👎