0

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.

  • So you're trying to circumvent the settings your admin has made for you ... probably with a reason ... and we should help you with this!? ... is that right? ;-) – Olaf Feb 25 '22 at 17:17
  • It's for a statistics display monitor in a warehouse. Our in house tech support team has wasted a month saying their working on a way for these machines to stay logged in and monitor on. My operations manager tasked me with doing it some way in the meantime. Support just keeps saying their working on it. – ScriptingConfusion Feb 25 '22 at 17:24
  • If they're willing to support this requirement they just should move this computer to another OU, diable the GPO for the energy settings and change the settings for this particular computer manually. So no need for a permanently running error prone script. ;-) – Olaf Feb 25 '22 at 17:34
  • Last I heard they said they cannot leave a terminal open because of SOX compliance. And that they have a digital signage solution but not until they get data provided in a particular format. Month later and nothing. We are not on their priority list clearly. – ScriptingConfusion Feb 25 '22 at 17:40
  • Hmmm ... ok ... I actually don't know if that's easily possible with PowerShell but I had a similar solution in place that moves the mouse pointer a few pixels forth and back every few minutes. It's been almost 20 years ago and I use AutoHotkey. ;-) – Olaf Feb 25 '22 at 17:45
  • I am using a few lines of powershell to move the mouse in my current script because I noticed they keystroke simulations were not keeping the monitor alive. if that should work maybe I should try a different method of mouse movement. will look into that. – ScriptingConfusion Feb 25 '22 at 17:53
  • what about: `$WShell = New-Object -Com "Wscript.Shell" while (1) {$WShell.SendKeys("{SCROLLLOCK}"); sleep 60}`? – Abraham Zinala Feb 25 '22 at 18:30
  • the scroll lock script I have works great and I can tell its working by the fact that screen lock is being avoided. but some reason despite that and a mouse movement (by 1 px) script my monitor still enters power saving after 20 minutes. I think its the monitor timeout setting in power management. but changing group policy is out of the question so i can only try workarounds. – ScriptingConfusion Feb 25 '22 at 18:35
  • 1
    Are you able to download VLC? We used to play a video on there on repeat to keep the monitor from timing out. A screen will wake up when it detects video signal sent to it. – Abraham Zinala Feb 25 '22 at 18:46
  • Definitely sounds plausible, I will try. – ScriptingConfusion Feb 25 '22 at 18:58
  • while I am able to install VLC, it seems it does not run or appear in program files afte I do. So I will have to test this with windows media player, which does have a repeat function, is there a safe place to acquire a video thats just a black screen or something at least with no sound? want as few steps as possible to instruct someone in using this. – ScriptingConfusion Feb 25 '22 at 19:20

2 Answers2

1

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

Buy a Mouse Jiggler

tanstaafl
  • 190
  • 5
  • 1
    Wow ... I'm amazed and shocked at the same time that such a device even exists. – Olaf Feb 25 '22 at 17:47
  • Well, they've got gaming mice that you can code your own scripts into. Figured probably something like this available. Sure he'd be breaking company SOX compliance, apparently, but his/his managers butt. – tanstaafl Feb 25 '22 at 17:52
  • This worked due to something I forgot to note: this is a thin client. It was not properly sending feedback to the monitor from windows that there was activity. The only way to get the monitor to see activity was from the mouse or keyboard physically, which a mouse jiggler usb mimicked. – ScriptingConfusion Mar 03 '22 at 15:40
1

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://learn.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.

Gurhan Polat
  • 696
  • 5
  • 12