View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Michel Pierron Michel Pierron is offline
external usenet poster
 
Posts: 214
Default Stop a running Screensaver .

Hi RAFAAJ2000,
You can try:

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

Sub ScreenSaverOff()
Call SetScreenSaver(False)
End Sub

Sub ScreenSaverOn()
Call SetScreenSaver(True)
End Sub

Private Sub SetScreenSaver(ByVal Enable As Boolean)
Dim Ret As Long
Ret = SystemParametersInfo(17, Enable, ByVal 0, 0)
If Ret = 0 Then MsgBox "Error !", 64
End Sub

MP


"RAFAAJ2000" a écrit dans le message
de news: ...
Steve,

Fantastic !....It works beautifully !......It never occured to me to use
the
WMI for solving this . I had been only exploring APIs so far.

Thank you very much indeed. :)

I am still curious to see a pure API solution only for the sake of
learning :)

Regards.


"Steve Yandl" wrote:

Try this.

_____________________________________

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process")

For Each objProcess in colProcesses
If Right(objProcess.Name, 4) = ".scr" Then
objProcess.Terminate
End If
Next

____________________________________

Steve




"RAFAAJ2000" wrote in message
...
Hi,

I am trying to turnoff a screensaver as soon as it kicks off.

I know how to detect if a screen saver is currently running via
SPI_GETSCREENSAVERRUNNING but I can't seem to STOP it once it has
kicked
off
programmatically.

I have tried simulating a Mouse Move or SendKey and even using the
SendMessage with the WM_CLOSE Msg but no luck !

Actually, I ma not sure about this, but it looks as if no code is
executed
once the screensaver kicks off as the lines of code subsequent to the
screensaver starting don't execute !

I am doing this in an XL macro under XL2002 WIN XP.

Any help on this ?

Regards.