A
A
Askush2018-07-09 11:32:45
Python
Askush, 2018-07-09 11:32:45

How to prevent computer from sleeping with python?

The demo computer with statistics falls asleep all the time. The problem is that at the domain level, a power management policy is rolled every two hours, which knocks down all local settings to standard ones. I tried to use a python script to do this that emulates mouse movement, but that didn't work
. Is there any solution?

import pyautogui
screenWidth, screenHeight = pyautogui.size()
pyautogui.moveTo(screenWidth / 2, screenHeight / 2)
pyautogui.moveTo(screenWidth / 3, screenHeight / 3)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
m0nym, 2018-07-09
@m0nym

Contact the system administrator who administers domain policies.
Explain the situation and ask to disable sleep for this particular computer.

E
Ezhyg, 2018-07-09
@Ezhyg

shutdown -a

Task for Scheduler - Cancel Shutdown
<?xml version="1.0" encoding="UTF-16" ?> 
- <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
- <RegistrationInfo>
  <Date>2018-07-09T11:57:08.396045</Date> 
  <Author>Тостер\ЁжЫГ</Author> 
  </RegistrationInfo>
- <Triggers>
- <EventTrigger>
  <Enabled>true</Enabled> 
  <Subscription><QueryList><Query Id="0" Path="System"><Select Path="System">*[System[Provider[@Name='USER32'] and EventID=1074]]</Select></Query></QueryList></Subscription> 
  </EventTrigger>
- <EventTrigger>
  <Enabled>true</Enabled> 
  <Subscription><QueryList><Query Id="0" Path="System"><Select Path="System">*[System[Provider[@Name='USER32'] and EventID=1076]]</Select></Query></QueryList></Subscription> 
  </EventTrigger>
- <EventTrigger>
  <Enabled>true</Enabled> 
  <Subscription><QueryList><Query Id="0" Path="System"><Select Path="System">*[System[Provider[@Name='USER32'] and (EventID=1074 or EventID=1076)]]</Select></Query></QueryList></Subscription> 
  </EventTrigger>
  </Triggers>
- <Principals>
- <Principal id="Author">
  <UserId>f-1\ЁжЫГ</UserId> 
  <LogonType>InteractiveToken</LogonType> 
  <RunLevel>LeastPrivilege</RunLevel> 
  </Principal>
  </Principals>
- <Settings>
  <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy> 
  <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries> 
  <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries> 
  <AllowHardTerminate>true</AllowHardTerminate> 
  <StartWhenAvailable>false</StartWhenAvailable> 
  <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable> 
- <IdleSettings>
  <StopOnIdleEnd>true</StopOnIdleEnd> 
  <RestartOnIdle>false</RestartOnIdle> 
  </IdleSettings>
  <AllowStartOnDemand>true</AllowStartOnDemand> 
  <Enabled>true</Enabled> 
  <Hidden>false</Hidden> 
  <RunOnlyIfIdle>false</RunOnlyIfIdle> 
  <WakeToRun>false</WakeToRun> 
  <ExecutionTimeLimit>P3D</ExecutionTimeLimit> 
  <Priority>7</Priority> 
  </Settings>
- <Actions Context="Author">
- <Exec>
  <Command>shutdown</Command> 
  <Arguments>-a</Arguments> 
  </Exec>
  </Actions>
  </Task>

A
alekssamos, 2018-07-11
@alekssamos

This is exactly what should work.
https://www.autoitscript.com/site/autoit/downloads/

#NoTrayIcon
If WinExists("antisleep") Then Exit 1
AutoItWinSetTitle("antisleep")
#include <Timers.au3>
While 1
  Sleep(1000)
  If _Timer_GetIdleTime() >= 1000 * 60 * 60 Then
    MouseMove(MouseGetPos(0)+2, MouseGetPos(1)+2)
    MouseMove(MouseGetPos(0)-2, MouseGetPos(1)-2)
  EndIf
WEnd

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question