Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Disable screen saver

0 views
Skip to first unread message

J. Shrimp, Jr.

unread,
Feb 10, 2005, 8:42:47 PM2/10/05
to
IT department has enabled a screen saver that inititates 15
minutes after inactivity. Would like to have a tiny VB
program that sends a key stroke to the screen every
fourteen minutes, so that the screen saver never starts.
Using Sleep (15 minutes) then sendkeys ("") didn't work.
Is there a simple mousemove event or some other way
to prevent the screen saver from kicking in?


Randy Birch

unread,
Feb 10, 2005, 10:11:38 PM2/10/05
to
I guess you could try a ShowCursor() api call, followed by a few
SetCursorPos() calls to move the rodent around the screen. Might even be
able to call GetForegroundWindow to get the hwnd of that then send a mouse
event to that window.

--


Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/


"J. Shrimp, Jr." <jumbo_...@hotmail.com> wrote in message
news:110o348...@corp.supernews.com...
: IT department has enabled a screen saver that inititates 15

:
:

Frank Adam

unread,
Feb 10, 2005, 10:56:10 PM2/10/05
to

Try keybd_event or Sendinput to the desktop ?

--

Regards, Frank

Kylesb

unread,
Feb 11, 2005, 1:29:12 AM2/11/05
to
Years ago, I had a need to prevent the screensaver from running in
win31. The following C code is how I did it, maybe the same approach
will work with the newer OSs, I'm not certain. The API calls should
be quite easy to use in VB (note these are win31 API calls).

{
/* get cursor position and move it */
btoggle=!btoggle;
GetCursorPos(&ptcursor);
if (btoggle)
SetCursorPos(ptcursor.x+1,ptcursor.y+1);
else
SetCursorPos(ptcursor.x-1,ptcursor.y-1);
}

A quick check of the win32 API help file shows the GetCursorPos and
SetCursorPos calls are still with us in win32.

--
Best regards,
Kyle
"J. Shrimp, Jr." <jumbo_...@hotmail.com> wrote in message
news:110o348...@corp.supernews.com...

Barry

unread,
Feb 13, 2005, 10:56:04 AM2/13/05
to
We have a similar problem but worked a different solution. Look at
the following function....

Public Function SetTimeOut(ByVal textin As String) As Long
Dim lng1 As Long
Dim inparam As Long
Dim outparam As Long

outparam = Val(textin) * 60
inparam = outparam
lng1 = SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, inparam, _
outparam, SPIF_UPDATEINIFILE)
If lng1 <> 0 Then
SetTimeOut = outparam
Else
SetTimeOut = 0
End If

End Function

Here are the declares....

Private Const SPI_GETSCREENSAVETIMEOUT As Long = 14
Private Const SPI_SETSCREENSAVETIMEOUT As Long = 15
Private Const SPIF_SENDWININICHANGE As Long = &H2
Private Const SPIF_SENDCHANGE As Long = SPIF_SENDWININICHANGE
Private Const SPIF_UPDATEINIFILE As Long = &H1

Private Declare Function SystemParametersInfo Lib "user32" Alias
"SystemParametersInfoA" ( _
ByVal uAction As Long, _
ByVal uParam As Long, _
ByRef lpvParam As Any, _
ByVal fuWinIni As Long) As Long


The SystemParametersInfo API will allow you to reset the time on the
ScreenSaver and stretch it out to whatever you want. I believe a "0"
will shut off the screensaver (but you have to confirm that).

HTH,
Barry

bceggersATcomcastDOTnet

Frank Adam

unread,
Feb 13, 2005, 5:05:40 PM2/13/05
to
On Sun, 13 Feb 2005 10:56:04 -0500, Barry <bceg...@castcom.com>
wrote:

For 2K+ you may also want to look at the SetThreadExecutionState()
API. It seems to be the ticket to switch off screen and power saves.
There was also a trappable (would require subclassing the main form)
broadcast message i thought, but can't put a finger on it.

>We have a similar problem but worked a different solution. Look at
>the following function....
>

<snip>
--

Regards, Frank

Barry

unread,
Feb 13, 2005, 11:27:03 PM2/13/05
to
Hi,

The msdn help says...

"This function does not stop the screen saver from executing either."

for this API call. Is the help file in error (again!!)?

I guess it would prevent poweroff/sleep/hibernation but not the
screensaver ??

bceggersATcomcastDOTnet

Frank Adam

unread,
Feb 14, 2005, 7:09:17 AM2/14/05
to
On Sun, 13 Feb 2005 23:27:03 -0500, Barry <bceg...@castcom.com>
wrote:

>Hi,
>
>The msdn help says...
>"This function does not stop the screen saver from executing either."
>

Huh, my MSDN doesn't say that ? Didn't check the online one yet.

>for this API call. Is the help file in error (again!!)?
>

Probably more like ambiguous. Again. :)


>I guess it would prevent poweroff/sleep/hibernation but not the
>screensaver ??
>

This is what mine says :
ES_DISPLAY_REQUIRED - Informs the system that the thread is performing
some operation that is not normally detected as display activity by
the system.
.....
Calling SetThreadExecutionState with ES_DISPLAY_REQUIRED prevents the
system from turning off the display by resetting the display idle
timer. Calling SetThreadExecutionState without ES_CONTINUOUS simply
resets the idle timer; to keep the display or system in the working
state, the thread must call SetThreadExecutionState periodically.

Note i haven't tested this. I just remembered the thread and happened
to stumble over it, so i thought it's worth a shot to bring attention
to it.

>
>On Mon, 14 Feb 2005 09:05:40 +1100, fa...@xxxxoptushome.com.au (Frank
>Adam) wrote:
>
>>On Sun, 13 Feb 2005 10:56:04 -0500, Barry <bceg...@castcom.com>
>>wrote:
>>
>>For 2K+ you may also want to look at the SetThreadExecutionState()
>>API. It seems to be the ticket to switch off screen and power saves.
>>There was also a trappable (would require subclassing the main form)
>>broadcast message i thought, but can't put a finger on it.
>>
>>>We have a similar problem but worked a different solution. Look at
>>>the following function....
>>>
>><snip>
>
>bceggersATcomcastDOTnet

--

Regards, Frank

0 new messages