13

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
  • 473
  • 1
  • 4
  • 12

2 Answers2

10

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
  • 201
0

The PowerShell script runs much longer than 10 hours.

The parameter $minutes has the value 36000 and is subtracted by 1 every 60 seconds -> 36000 minutes = 600 hours (25 days).

At 600 it would be 10 hours

param($minutes = 36000)
...
for ($i = 0; $i -lt $minutes; $i++) { <- subtract 1, 36000 times = 36000 minutes
  Start-Sleep -Seconds 60   <- waits 1 minute
...
}