Have you ever wondered, how to keep your laptop session active? And, why?
I will answer the "why" first.
While running a script, one doesn't want the laptop to go to sleep.
During a presentation/training
Despite of being in front of laptop, one is busy checking social media on mobile
I don't want to mention all the scenarios. However, last one is more significant I feel. Because, even if one working and is in front of your laptop your teams green mark changes to yellow even before the laptop gets locked suggesting user is unavilable.
How to keep #Teams active in Green color? Or, how to keep your laptop's sessionactive?
Keep on working as one may miss the time out window and laptop gets locked
Keep a track of time out windows, move the mouse or press any key on keyboar
Or be smart and put #PowerShell at work to press some keys and keep the session active
Script Keep-Active.Ps1 can be used. Copy it or download from Github.com https://github.com/singhsawalakh/PowerShell/blob/01e67f5dde36cb376c31bc09022101f3a58af204/Keep-Active.ps1
Now let me explain you the working of this script in short.
I have used a while loop with the codition $true to let the scipt run always.
[console]::NumberLock: helps to query the status of the NumLock key by accessing the [console] class's NumberLock property. It will return either $true (NumLock is on) or $false (NumLock is off).
if($numlockstatus -eq $false): I check if it is off. It should be pressed
Then I use (New-Object -ComObject WScript.Shell).SendKeys('{NUMLOCK}'): This effectively turns on the NumLock.
else: If the NumLock is already on the script emulate to press NumberLock twice(as I prefer the NUMLOCK to stay on.)
At end the script is set to sleep for 120 seconds
Overall, this script is designed to ensure that the NumLock key remains in an active state (on) consistently every 120 seconds, regardless of its previous status. It does this by checking the NumLock status, sending the NumLock keypress accordingly, and then sleeping for 120 seconds before repeating the process.
Note: You do not need administrative rights run this script. Enjoy!
Comments