Jump to content
Sign in to follow this  
twp

Screensaver, Sleep, Workstation Lock, and Power-Save Disabling

Recommended Posts

twp

Hi!

I'm pretty new when it comes to AutoIt. Would need a Function that prevents your computer from entering into any hibernate or screensaver during an installation. I have a script to install a complicated application but have run into problems with some computers locks the desktop before installation is complete. 
 
I've found something that I think would fit perfectly but from what I can see, the reset function resets the settings to the windows default. I want the settings to be reset to the previous value. Someone who can help me solve this? The script needs to work on win7 x86 and Win7 x64. 
 
Here's the function I'm talking about: 

Share this post


Link to post
Share on other sites
FireFox

Hi,

Welcome to the autoit forum :)

If you want to avoid screen lock you can simply move the mouse every X seconds or if the user is idle more than X seconds.

Local $aMgp = MouseGetPos()
MouseMove($aMgp[0], $aMgp[1] + 1, 1)
MouseMove($aMgp[0], $aMgp[1] - 1, 1)

 

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
water

You could use AdLibRegister to move the mouse every x seconds (every 60 seconds in the example):

AdlibRegister(_MouseMove, 1000*60)
While 1
    ; Replace While/Wend with your code
WEnd
Func _MouseMove()
    Local $aMgp = MouseGetPos()
    MouseMove($aMgp[0], $aMgp[1] + 1, 1)
    MouseMove($aMgp[0], $aMgp[1] - 1, 1)
EndFunc

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
JLogan3o13

If you are doing this while you're installing software, you could also set it up so it moves the mouse only while the process is active:

While ProcessExists("setup.exe")
    Local $aMgp = MouseGetPos()
    MouseMove($aMgp[0], $aMgp[1] + 1, 1)
    MouseMove($aMgp[0], $aMgp[1] - 1, 1)
    Sleep(1000 * 30)
WEnd
Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
BrewManNH

#include <APIProcConstants.au3>

DllCall('kernel32.dll','long', 'SetThreadExecutionState', 'long', BitOr($ES_CONTINUOUS, $ES_DISPLAY_REQUIRED, $ES_SYSTEM_REQUIRED))
While Sleep(100)
WEnd

This will disable the screensaver and the computer won't go into sleep mode.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
twp

Hi,

Welcome to the autoit forum :)

If you want to avoid screen lock you can simply move the mouse every X seconds or if the user is idle more than X seconds.

Local $aMgp = MouseGetPos()
MouseMove($aMgp[0], $aMgp[1] + 1, 1)
MouseMove($aMgp[0], $aMgp[1] - 1, 1)

Br, FireFox.

 

 

You could use AdLibRegister to move the mouse every x seconds (every 60 seconds in the example):

AdlibRegister(_MouseMove, 1000*60)
While 1
    ; Replace While/Wend with your code
WEnd
Func _MouseMove()
    Local $aMgp = MouseGetPos()
    MouseMove($aMgp[0], $aMgp[1] + 1, 1)
    MouseMove($aMgp[0], $aMgp[1] - 1, 1)
EndFunc

 

 

If you are doing this while you're installing software, you could also set it up so it moves the mouse only while the process is active:

While ProcessExists("setup.exe")
    Local $aMgp = MouseGetPos()
    MouseMove($aMgp[0], $aMgp[1] + 1, 1)
    MouseMove($aMgp[0], $aMgp[1] - 1, 1)
    Sleep(1000 * 30)
WEnd

 

I have tried to use the method that moves the mouse but do not really understand how I can implement it in my script. My script installs an application and during the installation, a few keystrokes are made. The script waits for boxes that are popping up in order to close them. It is a recording of keystrokes which I've modified a bit afterwards and added a few features that closes processes and so on. Have no idea how I implement a mouse move every minute in such a script, as in several minutes standing and waiting to perform a few keystrokes. 
 
Suggestions are appreciated.
Edited by twp

Share this post


Link to post
Share on other sites
JLogan3o13

Post your code. We've gone about as far as we can stumbling about in the dark, trying to divine just what you're trying to accomplish. Help us help you ;)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
twp
#include <APIProcConstants.au3>

DllCall('kernel32.dll','long', 'SetThreadExecutionState', 'long', BitOr($ES_CONTINUOUS, $ES_DISPLAY_REQUIRED, $ES_SYSTEM_REQUIRED))
While Sleep(100)
WEnd

This will disable the screensaver and the computer won't go into sleep mode.

 

This is similar to what I mentioned in the beginning and I like that: 
 
But how do I reset the settings to what they were before I changed them? You mention just how I shut down functions. Not how I restore them again. 
 
Really like this solution and would appreciate some help.

Share this post


Link to post
Share on other sites
BrewManNH

With the code I posted, use the DLLCall line at the start of your script. Then as long as your script is running that will keep it from going into sleep/hibernate. The While loop was just for a demonstration, you don't need it in your script. It will self enable sleep/hibernate after it closes.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
twp

Post your code. We've gone about as far as we can stumbling about in the dark, trying to divine just what you're trying to accomplish. Help us help you ;)

 

Do not have my code right now but it's basically like the example below:

;Run the Office 2010 installer
Run ("setup.exe")
;Wait for the setup window to be active
WinWaitActive ("Microsoft Office Professional Plus 2010", "setup")
;Accept the license agreement
Send (!a)
;Proceed to the next screen
Send (!c)
;Install Office with default options
WinWaitActive ("Microsoft Office Professional Plus 2010", "Choose the installation you want")
Send (!i)
;Close the setup when office is installed
WinWaitActive ("Microsoft Office Professional Plus 2010", "Setup Complete")
Send (!c)

Above this code, there are also some auto-generated function for WinWaitActive.

It takes just under an hour to install, and the wait can be quite long between inputs.

Edited by twp

Share this post


Link to post
Share on other sites
water

Why do you automate the installation GUI? Did you have a look at silent installation?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
twp
If I run a function to move the mouse between all these WinWaitActive step, then it will prevent these steps from executing. What should I do? 
 
Ideally, I'd turn off the computers/users ability to lock, shut down or go into sleep mode functions at the beginning of the script, and then restore everything if something goes wrong or when everything is ready. That is my goal! But if the mouse movement seems to be a better solution then let's go for that.

Share this post


Link to post
Share on other sites
twp

Why do you automate the installation GUI? Did you have a look at silent installation?

We have tested all that is possible to test when it comes to silent installation but it is unfortunately quite impossible in this unique case. It's an impossible application installation to silence.

Share this post


Link to post
Share on other sites
water

How do you think does the Microsoft SCCM tool roll out Office 2010?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
TXTechie

Microsoft Office installations are definitely very customizable and they can be installed quietly (with a limited GUI) or completely silently (no GUI or user-interaction). You need to download and use Microsoft's free Office Customization Tool in order to customize the Office installation to your needs. Here's the link for the Office Customization Tool for Office 2010.

Edited by TXTechie

Share this post


Link to post
Share on other sites
water

The Office Customization Tool (OCT) is used to create a Setup customization file (.msp file). Setup applies this file when Office is installed on the computers.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
twp

How do you think does the Microsoft SCCM tool roll out Office 2010?

 

Microsoft Office installations are definitely very customizable and they can be installed quietly (with a limited GUI) or completely silently (no GUI or user-interaction). You need to download and use Microsoft's free Office Customization Tool in order to customize the Office installation to your needs. Here's the link for the Office Customization Tool for Office 2010.

 

The Office Customization Tool (OCT) is used to create a Setup customization file (.msp file). Setup applies this file when Office is installed on the computers.

 

I'm sorry for the misunderstanding but it is not the office I'm trying to install. The script above is only an example! I'm trying to automate the installation of an old application for medical devices. Please and try not to focus on what I am trying to automate but how. I need to find a good way to prevent the computer from being locked or go into sleep mode/screen saver during installation.

Share this post


Link to post
Share on other sites
mrider

According to Microsoft's kernel32 documentation, you clear the flags by calling kernel32 again using only the ES_CONTINUOUS flag.  I've personally never done it - but if I'm reading the documentation correctly, the the code below should work.  (EDIT - here's a link to the API http://msdn.microsoft.com/en-us/library/aa373208%28VS.85%29.aspx )

#include <APIProcConstants.au3>

; Turn off screensaver, sleep, and etcetera
DllCall('kernel32.dll','long', 'SetThreadExecutionState', 'long', BitOr($ES_CONTINUOUS, $ES_DISPLAY_REQUIRED, $ES_SYSTEM_REQUIRED))

;Run the Office 2010 installer
Run ("setup.exe")
;Wait for the setup window to be active
WinWaitActive ("Microsoft Office Professional Plus 2010", "setup")
;Accept the license agreement
Send (!a) 
;Proceed to the next screen
Send (!c)
;Install Office with default options
WinWaitActive ("Microsoft Office Professional Plus 2010", "Choose the installation you want")
Send (!i) 
;Close the setup when office is installed 
WinWaitActive ("Microsoft Office Professional Plus 2010", "Setup Complete") 
Send (!c)

; Reset to normal mode
DllCall('kernel32.dll','long', 'SetThreadExecutionState', 'long', $ES_CONTINUOUS)
Edited by mrider

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Share this post


Link to post
Share on other sites
BrewManNH

As I said above, the code I posted will only affect Windows not going to sleep as long as that program is running. As soon as the program ends, so does the bypass of sleep and hibernate. Sometimes, it will allow the screensaver to kick in, but when you're automating the GUI that shouldn't matter because any sends or mouseclicks will just cause the screensaver to go away, and a screensaver shouldn't affect the script.

 

mrider's suggestion to explicitly turn it off is probably good practice just to make sure things get cleaned up after it's done.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
twp

 

According to Microsoft's kernel32 documentation, you clear the flags by calling kernel32 again using only the ES_CONTINUOUS flag.  I've personally never done it - but if I'm reading the documentation correctly, the the code below should work.  (EDIT - here's a link to the API http://msdn.microsoft.com/en-us/library/aa373208%28VS.85%29.aspx )

#include <APIProcConstants.au3>

; Turn off screensaver, sleep, and etcetera
DllCall('kernel32.dll','long', 'SetThreadExecutionState', 'long', BitOr($ES_CONTINUOUS, $ES_DISPLAY_REQUIRED, $ES_SYSTEM_REQUIRED))

;Run the Office 2010 installer
Run ("setup.exe")
;Wait for the setup window to be active
WinWaitActive ("Microsoft Office Professional Plus 2010", "setup")
;Accept the license agreement
Send (!a) 
;Proceed to the next screen
Send (!c)
;Install Office with default options
WinWaitActive ("Microsoft Office Professional Plus 2010", "Choose the installation you want")
Send (!i) 
;Close the setup when office is installed 
WinWaitActive ("Microsoft Office Professional Plus 2010", "Setup Complete") 
Send (!c)

; Reset to normal mode
DllCall('kernel32.dll','long', 'SetThreadExecutionState', 'long', $ES_CONTINUOUS)

 

As I said above, the code I posted will only affect Windows not going to sleep as long as that program is running. As soon as the program ends, so does the bypass of sleep and hibernate. Sometimes, it will allow the screensaver to kick in, but when you're automating the GUI that shouldn't matter because any sends or mouseclicks will just cause the screensaver to go away, and a screensaver shouldn't affect the script.

 

mrider's suggestion to explicitly turn it off is probably good practice just to make sure things get cleaned up after it's done.

 

I will give it a try and see if it works. Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.