Home > Net >  Delaying monitor timeout without admin via powershell
Delaying monitor timeout without admin via powershell

Time:02-27

I am using a powershell script to keep a windows pc logged in defying its group policy, however after 20 minutes the monitor turns off after displaying a "no signal" message.

The script I am using is one that toggles scroll lock to simulate input and keep the user logged in. Usually the computer locks and has you press ctrl alt del and then enter your password to unlock after 15 minutes. The script works to keep me logged in and avoid the lock, but not keep the monitor on, which is my goal here. End goal being that I can stay logged in and the monitor on for about 12 hours.

I have no admin privileges and have to use -ep bypass to even run my script.

CodePudding user response:

If you have access to USB could go for something like this...

Buy a Mouse Jiggler

CodePudding user response:

You just need to call SetThreadExecutionState with ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED parameter. (which is 0x02 | 0x01 = 0x03)

Below code is a sample how to do it.

Add-Type -TypeDefinition @"
 using System;
 using System.Diagnostics;
 using System.Runtime.InteropServices;

 public static class Kernel32
 {
     [DllImport("Kernel32.dll", CharSet=CharSet.Auto)]
      public static extern uint SetThreadExecutionState(uint dwExecutionState);
 }
"@

[Kernel32]::SetThreadExecutionState(0x03)

Remarks: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate#remarks

Multimedia applications, such as video players and presentation applications, must use ES_DISPLAY_REQUIRED when they display video for long periods of time without user input.

I don't have much knowledge about powershell but it seems correct to me. But You need exactly this API call, I'm pretty sure.

  • Related