Closing NT4's screen saver - contains code 
Author Message
 Closing NT4's screen saver - contains code

All:
Should be simple. Yes?  NOT!
I am trying to close the screen saver in NT with the following, and I
cannot tell what the problem with my code is (!)
Through logging, I can see that the program can detect when the screen
saver starts, but I have been unable to terminate the screen
saver once it begins.  I have looked at the MS bulletins, and a post
by Don Bradner (thanks Don!) but to no avail.
I made a form with a timer that checks once per second to see if the
screen saver has started, hopefully to trigger the code that
will terminate it.  (Later I will start the .exe file via the
AT command, (and without the timer) but I need to get this working
first!)
Note that NT4's screen saver is on a different desktop...
Help anyone?

'in a form with a timer:
Private sub timer1_timer()
    Dim hdesktop, templong as long
    if NTSaverRunning() = True them
        templong = EnumDesktopWindows(hdesktop, AddressOf
KillSreenSaverFunc, &H0)
        CloseDesktop (templong)
    endif
end sub

'in a module:
Declare Function OpenDesktop& Lib "user32" _
    Alias "OpenDesktopA" (ByVal lpszDesktop$, ByVal DwFlags$, _
    ByVal flnherit&, ByVal dwDesiredAccess&)

Declare Function CloseDesktop Lib "user32" _
    (ByVal hDesktop as Long) as Long

Declare Function EnumDesktopWindows Lib "user32" _
    (ByVal hDesktop as Long, ByVal lpfn as Long, ByVal lParam as Long)
as Long

Declare Function IsWindowVisible Lib "user32" _
    (ByVal hDesktop as Long) as Long

Declare Function PostMessage Lib "user32" _
    Alias "PostMessageA"  (ByVal hwnd as Long, ByVal sMgs as Long, _
    ByVal wParam as Long, lParam as Any) as Long

Public Const MAXIMUM_ALLOWED = &H2000000
Public Const WM_CLOSE = &H10

Public Function NTSaverRunning() as Boolean
    Dim HDesktop as Long
    NTSAVERRunning = False
    hDesktop = OpenDeskTop("Screen-saver", 0&, _
        0&, MAXIMUM_ALLOWED)
    If HDesktop = 0 then
        If Err.LastDllError = 5 then
            NTSaverRuning = True
        End If
    Else
        NTSaverRunning = True
    End If
End Function

Public Function KillScreenSaverFunc(HDesktop As Long, LParam As Long)
    hDesktop  = OpenDesktop("Screen-saver", 0&, 0&, MAXIMUM_ALLOWED)
    If hDesktop <> 0 then
        If IsWindowVisible(hDesktop) then
            PostMessage hDesktop, WM_CLOSE, ByVal CLng(0), _
                ByValCLng(0)
        End If
    End If
End Function



Mon, 31 May 2004 06:11:10 GMT  
 Closing NT4's screen saver - contains code

Quote:

>All:
>Should be simple. Yes?  NOT!
>I am trying to close the screen saver in NT with the following, and I
>cannot tell what the problem with my code is (!)
>Through logging, I can see that the program can detect when the screen
>saver starts, but I have been unable to terminate the screen
>saver once it begins.  I have looked at the MS bulletins, and a post
>by Don Bradner (thanks Don!) but to no avail.
>I made a form with a timer that checks once per second to see if the
>screen saver has started, hopefully to trigger the code that
>will terminate it.  (Later I will start the .exe file via the
>AT command, (and without the timer) but I need to get this working
>first!)
>Note that NT4's screen saver is on a different desktop...
>Help anyone?

I had to make quite a few changes to your code to get it to work. Let
me know if you can't follow them. Tested only on XP, but the principle
is the same, so give it a try on NT.

Option Explicit
Private Sub timer1_timer()
    Dim HDesktop As Long, templong As Long
    HDesktop = OpenDesktop("Screen-saver", 0&, _
        0&, DESKTOP_READOBJECTS Or DESKTOP_WRITEOBJECTS)
    If HDesktop <> 0 Then
        templong = EnumDesktopWindows(HDesktop, AddressOf
KillScreenSaverFunc, &H0)
        CloseDesktop (HDesktop)
    End If
End Sub

Option Explicit
Declare Function OpenDesktop& Lib "user32" _
    Alias "OpenDesktopA" (ByVal lpszDesktop$, ByVal DwFlags$, _
    ByVal flnherit&, ByVal dwDesiredAccess&)

Declare Function CloseDesktop Lib "user32" _
    (ByVal HDesktop As Long) As Long

Declare Function EnumDesktopWindows Lib "user32" _
    (ByVal HDesktop As Long, ByVal lpfn As Long, ByVal LParam As Long)
As Long

Declare Function IsWindowVisible Lib "user32" _
    (ByVal HDesktop As Long) As Long

Declare Function PostMessage Lib "user32" _
    Alias "PostMessageA" (ByVal HWnd As Long, ByVal sMgs As Long, _
    ByVal wParam As Long, LParam As Any) As Long

Public Const WM_CLOSE = &H10
Public Const DESKTOP_READOBJECTS = &H1&
Public Const DESKTOP_WRITEOBJECTS = &H80&

Public Function KillScreenSaverFunc(ByVal HWnd As Long, ByVal LParam
As Long) As Long
    If HWnd <> 0 Then
        If IsWindowVisible(HWnd) Then
             PostMessage HWnd, WM_CLOSE, 0&, 0&
        End If
    End If
    KillScreenSaverFunc = 1
End Function

- Show quoted text -

Quote:
>'in a form with a timer:
>Private sub timer1_timer()
>    Dim hdesktop, templong as long
>    if NTSaverRunning() = True them
>        templong = EnumDesktopWindows(hdesktop, AddressOf
>KillSreenSaverFunc, &H0)
>        CloseDesktop (templong)
>    endif
>end sub

>'in a module:
>Declare Function OpenDesktop& Lib "user32" _
>    Alias "OpenDesktopA" (ByVal lpszDesktop$, ByVal DwFlags$, _
>    ByVal flnherit&, ByVal dwDesiredAccess&)

>Declare Function CloseDesktop Lib "user32" _
>    (ByVal hDesktop as Long) as Long

>Declare Function EnumDesktopWindows Lib "user32" _
>    (ByVal hDesktop as Long, ByVal lpfn as Long, ByVal lParam as Long)
>as Long

>Declare Function IsWindowVisible Lib "user32" _
>    (ByVal hDesktop as Long) as Long

>Declare Function PostMessage Lib "user32" _
>    Alias "PostMessageA"  (ByVal hwnd as Long, ByVal sMgs as Long, _
>    ByVal wParam as Long, lParam as Any) as Long

>Public Const MAXIMUM_ALLOWED = &H2000000
>Public Const WM_CLOSE = &H10

>Public Function NTSaverRunning() as Boolean
>    Dim HDesktop as Long
>    NTSAVERRunning = False
>    hDesktop = OpenDeskTop("Screen-saver", 0&, _
>        0&, MAXIMUM_ALLOWED)
>    If HDesktop = 0 then
>        If Err.LastDllError = 5 then
>            NTSaverRuning = True
>        End If
>    Else
>        NTSaverRunning = True
>    End If
>End Function

>Public Function KillScreenSaverFunc(HDesktop As Long, LParam As Long)
>    hDesktop  = OpenDesktop("Screen-saver", 0&, 0&, MAXIMUM_ALLOWED)
>    If hDesktop <> 0 then
>        If IsWindowVisible(hDesktop) then
>            PostMessage hDesktop, WM_CLOSE, ByVal CLng(0), _
>                ByValCLng(0)
>        End If
>    End If
>End Function

--
Don Bradner

MVP Visual Basic


Mon, 31 May 2004 15:25:04 GMT  
 Closing NT4's screen saver - contains code

Quote:
> Thanks for the assistance.  This works great!

Mike Stanton
Quote:

> I had to make quite a few changes to your code to get it to work. Let
> me know if you can't follow them. Tested only on XP, but the principle
> is the same, so give it a try on NT.

> Option Explicit
> Private Sub timer1_timer()
>     Dim HDesktop As Long, templong As Long
>     HDesktop = OpenDesktop("Screen-saver", 0&, _
>         0&, DESKTOP_READOBJECTS Or DESKTOP_WRITEOBJECTS)
>     If HDesktop <> 0 Then
>         templong = EnumDesktopWindows(HDesktop, AddressOf
> KillScreenSaverFunc, &H0)
>         CloseDesktop (HDesktop)
>     End If
> End Sub

> Option Explicit
> Declare Function OpenDesktop& Lib "user32" _
>     Alias "OpenDesktopA" (ByVal lpszDesktop$, ByVal DwFlags$, _
>     ByVal flnherit&, ByVal dwDesiredAccess&)

> Declare Function CloseDesktop Lib "user32" _
>     (ByVal HDesktop As Long) As Long

> Declare Function EnumDesktopWindows Lib "user32" _
>     (ByVal HDesktop As Long, ByVal lpfn As Long, ByVal LParam As Long)
> As Long

> Declare Function IsWindowVisible Lib "user32" _
>     (ByVal HDesktop As Long) As Long

> Declare Function PostMessage Lib "user32" _
>     Alias "PostMessageA" (ByVal HWnd As Long, ByVal sMgs As Long, _
>     ByVal wParam As Long, LParam As Any) As Long

> Public Const WM_CLOSE = &H10
> Public Const DESKTOP_READOBJECTS = &H1&
> Public Const DESKTOP_WRITEOBJECTS = &H80&

> Public Function KillScreenSaverFunc(ByVal HWnd As Long, ByVal LParam
> As Long) As Long
>     If HWnd <> 0 Then
>         If IsWindowVisible(HWnd) Then
>              PostMessage HWnd, WM_CLOSE, 0&, 0&
>         End If
>     End If
>     KillScreenSaverFunc = 1
> End Function

> >'in a form with a timer:
> >Private sub timer1_timer()
> >    Dim hdesktop, templong as long
> >    if NTSaverRunning() = True them
> >        templong = EnumDesktopWindows(hdesktop, AddressOf
> >KillSreenSaverFunc, &H0)
> >        CloseDesktop (templong)
> >    endif
> >end sub

> >'in a module:
> >Declare Function OpenDesktop& Lib "user32" _
> >    Alias "OpenDesktopA" (ByVal lpszDesktop$, ByVal DwFlags$, _
> >    ByVal flnherit&, ByVal dwDesiredAccess&)

> >Declare Function CloseDesktop Lib "user32" _
> >    (ByVal hDesktop as Long) as Long

> >Declare Function EnumDesktopWindows Lib "user32" _
> >    (ByVal hDesktop as Long, ByVal lpfn as Long, ByVal lParam as Long)
> >as Long

> >Declare Function IsWindowVisible Lib "user32" _
> >    (ByVal hDesktop as Long) as Long

> >Declare Function PostMessage Lib "user32" _
> >    Alias "PostMessageA"  (ByVal hwnd as Long, ByVal sMgs as Long, _
> >    ByVal wParam as Long, lParam as Any) as Long

> >Public Const MAXIMUM_ALLOWED = &H2000000
> >Public Const WM_CLOSE = &H10

> >Public Function NTSaverRunning() as Boolean
> >    Dim HDesktop as Long
> >    NTSAVERRunning = False
> >    hDesktop = OpenDeskTop("Screen-saver", 0&, _
> >        0&, MAXIMUM_ALLOWED)
> >    If HDesktop = 0 then
> >        If Err.LastDllError = 5 then
> >            NTSaverRuning = True
> >        End If
> >    Else
> >        NTSaverRunning = True
> >    End If
> >End Function

> >Public Function KillScreenSaverFunc(HDesktop As Long, LParam As Long)
> >    hDesktop  = OpenDesktop("Screen-saver", 0&, 0&, MAXIMUM_ALLOWED)
> >    If hDesktop <> 0 then
> >        If IsWindowVisible(hDesktop) then
> >            PostMessage hDesktop, WM_CLOSE, ByVal CLng(0), _
> >                ByValCLng(0)
> >        End If
> >    End If
> >End Function

> --
> Don Bradner

> MVP Visual Basic



Thu, 03 Jun 2004 00:49:37 GMT  
 Closing NT4's screen saver - contains code
Why are you trying to shut down a screen saver?  Sounds like another half
assed VB attempt to hack.  You idiots are causing enough trouble with Visual
Basic and outlook express.

Quote:

> >All:
> >Should be simple. Yes?  NOT!
> >I am trying to close the screen saver in NT with the following, and I
> >cannot tell what the problem with my code is (!)
> >Through logging, I can see that the program can detect when the screen
> >saver starts, but I have been unable to terminate the screen
> >saver once it begins.  I have looked at the MS bulletins, and a post
> >by Don Bradner (thanks Don!) but to no avail.
> >I made a form with a timer that checks once per second to see if the
> >screen saver has started, hopefully to trigger the code that
> >will terminate it.  (Later I will start the .exe file via the
> >AT command, (and without the timer) but I need to get this working
> >first!)
> >Note that NT4's screen saver is on a different desktop...
> >Help anyone?

> I had to make quite a few changes to your code to get it to work. Let
> me know if you can't follow them. Tested only on XP, but the principle
> is the same, so give it a try on NT.

> Option Explicit
> Private Sub timer1_timer()
>     Dim HDesktop As Long, templong As Long
>     HDesktop = OpenDesktop("Screen-saver", 0&, _
>         0&, DESKTOP_READOBJECTS Or DESKTOP_WRITEOBJECTS)
>     If HDesktop <> 0 Then
>         templong = EnumDesktopWindows(HDesktop, AddressOf
> KillScreenSaverFunc, &H0)
>         CloseDesktop (HDesktop)
>     End If
> End Sub

> Option Explicit
> Declare Function OpenDesktop& Lib "user32" _
>     Alias "OpenDesktopA" (ByVal lpszDesktop$, ByVal DwFlags$, _
>     ByVal flnherit&, ByVal dwDesiredAccess&)

> Declare Function CloseDesktop Lib "user32" _
>     (ByVal HDesktop As Long) As Long

> Declare Function EnumDesktopWindows Lib "user32" _
>     (ByVal HDesktop As Long, ByVal lpfn As Long, ByVal LParam As Long)
> As Long

> Declare Function IsWindowVisible Lib "user32" _
>     (ByVal HDesktop As Long) As Long

> Declare Function PostMessage Lib "user32" _
>     Alias "PostMessageA" (ByVal HWnd As Long, ByVal sMgs As Long, _
>     ByVal wParam As Long, LParam As Any) As Long

> Public Const WM_CLOSE = &H10
> Public Const DESKTOP_READOBJECTS = &H1&
> Public Const DESKTOP_WRITEOBJECTS = &H80&

> Public Function KillScreenSaverFunc(ByVal HWnd As Long, ByVal LParam
> As Long) As Long
>     If HWnd <> 0 Then
>         If IsWindowVisible(HWnd) Then
>              PostMessage HWnd, WM_CLOSE, 0&, 0&
>         End If
>     End If
>     KillScreenSaverFunc = 1
> End Function

> >'in a form with a timer:
> >Private sub timer1_timer()
> >    Dim hdesktop, templong as long
> >    if NTSaverRunning() = True them
> >        templong = EnumDesktopWindows(hdesktop, AddressOf
> >KillSreenSaverFunc, &H0)
> >        CloseDesktop (templong)
> >    endif
> >end sub

> >'in a module:
> >Declare Function OpenDesktop& Lib "user32" _
> >    Alias "OpenDesktopA" (ByVal lpszDesktop$, ByVal DwFlags$, _
> >    ByVal flnherit&, ByVal dwDesiredAccess&)

> >Declare Function CloseDesktop Lib "user32" _
> >    (ByVal hDesktop as Long) as Long

> >Declare Function EnumDesktopWindows Lib "user32" _
> >    (ByVal hDesktop as Long, ByVal lpfn as Long, ByVal lParam as Long)
> >as Long

> >Declare Function IsWindowVisible Lib "user32" _
> >    (ByVal hDesktop as Long) as Long

> >Declare Function PostMessage Lib "user32" _
> >    Alias "PostMessageA"  (ByVal hwnd as Long, ByVal sMgs as Long, _
> >    ByVal wParam as Long, lParam as Any) as Long

> >Public Const MAXIMUM_ALLOWED = &H2000000
> >Public Const WM_CLOSE = &H10

> >Public Function NTSaverRunning() as Boolean
> >    Dim HDesktop as Long
> >    NTSAVERRunning = False
> >    hDesktop = OpenDeskTop("Screen-saver", 0&, _
> >        0&, MAXIMUM_ALLOWED)
> >    If HDesktop = 0 then
> >        If Err.LastDllError = 5 then
> >            NTSaverRuning = True
> >        End If
> >    Else
> >        NTSaverRunning = True
> >    End If
> >End Function

> >Public Function KillScreenSaverFunc(HDesktop As Long, LParam As Long)
> >    hDesktop  = OpenDesktop("Screen-saver", 0&, 0&, MAXIMUM_ALLOWED)
> >    If hDesktop <> 0 then
> >        If IsWindowVisible(hDesktop) then
> >            PostMessage hDesktop, WM_CLOSE, ByVal CLng(0), _
> >                ByValCLng(0)
> >        End If
> >    End If
> >End Function

> --
> Don Bradner

> MVP Visual Basic



Fri, 04 Jun 2004 09:53:59 GMT  
 Closing NT4's screen saver - contains code

Quote:

>Why are you trying to shut down a screen saver?  Sounds like another half
>assed VB attempt to hack.  You idiots are causing enough trouble with Visual
>Basic and outlook express.

There are lots of reasons why it is necessary to shut down a screen
saver, primarily when it's high CPU load is going to interfere with a
scheduled process. That is why the code referenced is simply a
reworking of C code published by Microsoft in a KB article.

Do not confuse this with a security issue. The shutdown of a screen
saver via software will not bypass password protection anymore than if
it was physically shutdown via mouse movement.

--
Don Bradner

MVP Visual Basic



Fri, 04 Jun 2004 14:53:35 GMT  
 Closing NT4's screen saver - contains code
I agree, turning off a screensaver isn't necessarily an attempt at hacking.
The CPU requirement on older computers makes turning off a screensaver
necessary.

--
John Bickmore
www.bicyclecam.com
www.feed-zone.com


Quote:

> >Why are you trying to shut down a screen saver?  Sounds like another half
> >assed VB attempt to hack.  You idiots are causing enough trouble with
Visual
> >Basic and outlook express.

> There are lots of reasons why it is necessary to shut down a screen
> saver, primarily when it's high CPU load is going to interfere with a
> scheduled process. That is why the code referenced is simply a
> reworking of C code published by Microsoft in a KB article.

> Do not confuse this with a security issue. The shutdown of a screen
> saver via software will not bypass password protection anymore than if
> it was physically shutdown via mouse movement.

> --
> Don Bradner

> MVP Visual Basic



Wed, 16 Jun 2004 13:10:53 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Screen Saver Preview (Based off Jens's Code)

2. Hiding a form while a screen saver is active (VB5/NT4)

3. Screen Saver Preview under NT4.0

4. Starting a VB5 Screen Saver on Win NT4.x

5. Screen Saver on top of Screen Saver problem

6. Screen saver 'preview window'?

7. Timer to Close Database after Inactivity gets Overriden by Screen Saver

8. Screen Savers - Closing

9. (Access/Word Merge) Automating Closing of Main Doc Containing Merge Codes

10. PowerBasic code for screen saver?

11. Screen Saver Code

12. vb screen saver code

 

 
Powered by phpBB® Forum Software