Advertisement
Combreal

hiddenScreenSaver.ps1

Sep 21st, 2020
1,683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Shutdown displays after 5 seconds
  2. #Save as hiddenScreenSaver.ps1 and put the script in C:\Temp
  3.  
  4. Add-Type @'
  5. using System;
  6. using System.Diagnostics;
  7. using System.Runtime.InteropServices;
  8.  
  9. namespace PInvoke.Win32 {
  10.  
  11.    public static class UserInput {
  12.  
  13.        [DllImport("user32.dll", SetLastError=false)]
  14.        private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
  15.  
  16.        [StructLayout(LayoutKind.Sequential)]
  17.        private struct LASTINPUTINFO {
  18.            public uint cbSize;
  19.            public int dwTime;
  20.        }
  21.  
  22.        public static DateTime LastInput {
  23.            get {
  24.                DateTime bootTime = DateTime.UtcNow.AddMilliseconds(-Environment.TickCount);
  25.                DateTime lastInput = bootTime.AddMilliseconds(LastInputTicks);
  26.                return lastInput;
  27.            }
  28.        }
  29.  
  30.        public static TimeSpan IdleTime {
  31.            get {
  32.                return DateTime.UtcNow.Subtract(LastInput);
  33.            }
  34.        }
  35.  
  36.        public static int LastInputTicks {
  37.            get {
  38.                LASTINPUTINFO lii = new LASTINPUTINFO();
  39.                lii.cbSize = (uint)Marshal.SizeOf(typeof(LASTINPUTINFO));
  40.                GetLastInputInfo(ref lii);
  41.                return lii.dwTime;
  42.            }
  43.        }
  44.    }
  45. }
  46. '@
  47.  
  48. $boolCheck = $false
  49.  
  50. while($true)
  51. {
  52.     if([PInvoke.Win32.UserInput]::IdleTime -gt '00:00:05.0000000')
  53.     {
  54.         if(-Not $boolCheck)
  55.         {
  56.             & 'C:\WINDOWS\system32\scrnsave.scr' @('/s')
  57.             Start-Sleep -Seconds 1
  58.             $boolCheck = $true
  59.         }
  60.     }
  61.     else
  62.     {
  63.         $boolCheck = $false
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement