Created On:  23 July 2010

SilkTest requires that the screensaver is disabled to be able to successfully run tests. The policy applied to my PC does not allow me to deactivate the screensaver, so can I do this through SilkTest?

If the policy applied to your PC allows you to install software then it is probable that SilkTest can read and write to the registry. If this is the case, the following code will turn the screensaver on and off programmatically:-


[ ] //Include the user32.dll so we can access system functions to disable and enable the screensaver
[-] dll "user32.dll"
 [ ] //Enable the user32.dll file
 [ ] LONG SystemParametersInfo (LONG uAction, LONG uParam, LONG lpvParam, LONG fuWinIni) alias "SystemParametersInfoA"
[ ]
[ ] //Disable the screensaver
[-] void DisableScreenSaver ()
 [ ] //Call the user32.dll passing the parameters to disable the screensaver
 [ ] SystemParametersInfo (17, 0, 0, 0)
[ ]
[ ] //Enable the screensaver
[-] void EnableScreenSaver ()
 [ ] //Call the user32.dll passing the parameters to enable the screensaver
 [ ] SystemParametersInfo (17, 1, 0, 0)
 [ ] 
[ ] // Proof-of-concept testcase
[-] testcase EnableDisable() appstate none
 [ ] print("Disabling.....")
 [ ] DisableScreenSaver ()
 [ ] // Sleep for a period longer than the screensaver timeout (set to two minutes for this testcase)
 [ ] print("Sleeping")
 [ ] sleep(240) 
 [ ] EnableScreenSaver ()
 [ ] print("Waking....")
[ ]