6

Is there a Windows equivalent of the caffeinate utility on OS X? I want to have fairly aggressive logout settings in general, but have a dedicated program that prevents logout while it is running as a way of overriding this setting.

The caffeinate utility prevents logout as long as it is active, which is nice. caffeinate is a C program distributed by Apple. The source code to it is here .

I found a Powershell script that's roughly equivalent to it here and have been using a trivial modification of it shown below.

param($minutes = 36000)

$myshell = New-Object -com "Wscript.Shell"

for ($i = 0; $i -lt $minutes; $i++) {
  Start-Sleep -Seconds 60
  $myshell.sendkeys(".")
}

It sends a . keystroke to the graphical shell (and hence whatever application has focus) once a minute for 10 hours by default.

This means that you have to be vigilant when typing or else a stray . will appear once a minute, which is less than ideal.

Is there a more elegant way to write a program that disables logout, but only when it's running?

Greg Nisbet
  • 373
  • 3
  • 11
  • 1
    You could probably use autoit or auto hotkey to press and release the shift or control key very quickly. Or do the same with your powershell script. Using one of the meta keys would be better as most applications expect it to be used as a modifier rather than pressed alone, not sure if it would work in powershell or how you send it... otherwise an application would be [caffeine](http://www.zhornsoftware.co.uk/caffeine/) – Mokubai Dec 09 '18 at 23:19
  • @Mokubai Can you send a shift key by itself without autoit or autohotkey? Otherwise, the most harmless key I can find to prevent timeouts is `"{SCROLLLOCK}"`. although admittedly I'm not sure this is the right documentation: https://docs.microsoft.com/en-us/previous-versions/office/developer/office-xp/aa202943(v=office.10) – Greg Nisbet Dec 10 '18 at 00:11
  • 3
    There's Caffeine for Windows and many alternatives. https://alternativeto.net/software/caffeine-for-windows/ This question belongs in Software Recommendations, though. – DrMoishe Pippik Dec 10 '18 at 02:03
  • @GregNisbet yes, from PowerShell you can call any Windows APIs so it can do anything a native program can do – phuclv Jul 27 '23 at 01:12

1 Answers1

1

windows PowerToys has an app called Awake. There is both GUI and CLI option.

PowerToys Awake does not modify any of the Windows power plan settings, and does not depend on a custom power plan configuration. Instead, it spawns background threads that tell Windows that they require a specific state of the machine.

PowerToys Awake is a utility tool for Windows designed to keep a computer awake without having to manage its power & sleep settings. This behavior can be helpful when running time-consuming tasks, ensuring that the computer does not go to sleep or turn off its screens.

ns15
  • 111
  • 3