Ask a Question

Interrupt for Screensaver

smitad
Occasional Contributor

Interrupt for Screensaver

Hi,



I want to write an interrupt for Screensaver(VB Script) until my tests are running. Checked with WMI, TC is not supporting it. Has anyone done this. Please share some pointers.



Regards

Smita
11 REPLIES 11
karkadil
Valued Contributor

The easiest way to disable sceensaver for test run is to completely disable it πŸ™‚
karkadil
Valued Contributor

And here is a JScript example how to disable screensaver. If you really need this, you'll need to rewrite this in VBScript (see TC help topic "How to Call a DLL Routine From Your Script"). However, I still recommend just disable screen saver on you PC.



function DisableScreensaver()

{

  kernel = DLL.DefineDLL("kernel32");

  Lib = DLL.Load("c:\\Windows\\System32\\kernel32.dll");

  proc = kernel.DefineProc("SetThreadExecutionState", vt_void);

  Lib.SetThreadExecutionState();

}
HKosova
SmartBear Alumni (Retired)

Hi Smita,



In addition to Gennadiy's answer, you can prevent a screen saver from starting in the following ways:



* Call the Windows API SystemParametersInfo function to temporarily disable the screen saver:



' Disable the screen saver

Call Win32API.SystemParametersInfo(Win32API.SPI_SETSCREENSAVEACTIVE, False, Null, 0)



' Do something



' Enable the screen saver

Call Win32API.SystemParametersInfo(Win32API.SPI_SETSCREENSAVEACTIVE, True, Null, 0)





* Create a timer that will fire periodically and move the mouse pointer on the screen:



Sub Test

  Set timer = Utils.Timers.Add(900, "Unit1.MoveMouse", True)

 

  ' Do something

End Sub

 

Sub MoveMouse

  Sys.Desktop.MouseX = Sys.Desktop.MouseX + 1

End Sub


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
smitad
Occasional Contributor

Thanks Gennadiy and Helen. Will try this out and let you know.



Regards

Smita
googleid_102416
Contributor

function DisableScreensaver()

{

  kernel = DLL.DefineDLL("kernel32");

  Lib = DLL.Load("c:\\Windows\\System32\\kernel32.dll");

  proc = kernel.DefineProc("SetThreadExecutionState", vt_void);

  Lib.SetThreadExecutionState(); 

}



Looks like this is what I need, but this code rises an exeption:





---------------------------


TestComplete


---------------------------


JScript runtime error.


 


An exception occurred: 0xC0000005; class: ; description: ''


 


---------------------------


OK   


---------------------------


 

Any ideas why this is happening?
karkadil
Valued Contributor

Don't use this example. After some investigations I found out that it doesn't work. Anyway, even if you make it working, it will not disable the screensaver.



Please use Helen's suggestion instead.
googleid_102416
Contributor

Don't care too much about screensaver. I need to prevent the system from entering sleep or turning off the display. MSDN says this function (SetThreadExecutionState) should help, but I have no idea how to make it working:



http://msdn.microsoft.com/en-us/library/windows/desktop/aa373208(v=vs.85).aspx
karkadil
Valued Contributor

The correct solution for you is




function disableSleep()


{


  var ES_SYSTEM_REQUIRED = 0x00000001;


  var ES_DISPLAY_REQUIRED = 0x00000002;


  


  var kernel = DLL.DefineDLL("kernel32");


  var lib = DLL.Load("c:\\Windows\\System32\\kernel32.dll");


  var proc = kernel.DefineProc("SetThreadExecutionState", vt_i2, vt_void);


  lib.SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);


}



But since it only sends command to OS, but not sets some kind of settings, you need to run it from time to time. For instanse, you can create Timer and call this function every minute.
simon_glet
Regular Contributor

Hi,



This is all about the power scheme. If you need to configure your machine programmatically use powercfg.exe (doc).



An easy way to do this is to configure a power scheme, export it and import it on the target machine.



Sincerely
Simon Glet
cancel
Showing results forΒ 
Search instead forΒ 
Did you mean:Β