Option Explicit Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type Private Const VER_PLATFORM_WIN32_WINDOWS = 1 Private Const VER_PLATFORM_WIN32_NT = 2 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 Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function OpenDesktop Lib "user32" Alias "OpenDesktopA" (ByVal lpszDesktop As String, ByVal dwFlags As Long, ByVal fInherit As Boolean, ByVal dwDesiredAccess As Long) As Long Private Declare Function CloseDesktop Lib "user32" (ByVal hDesktop As Long) As Long Private Declare Function EnumDesktopWindows Lib "user32" (ByVal hDesktop As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long Private Const SC_SCREENSAVE = &HF140& Private Const SPI_GETSCREENSAVEACTIVE = 16 Private Const SPI_SCREENSAVERRUNNING = 97 Private Const SPI_SETSCREENSAVEACTIVE = 17 Private Const SPIF_NOINIFILE = &H0 Private Const SPIF_SENDWININICHANGE = &H2 Private Const SPIF_UPDATEINIFILE = &H1 Private Const DESKTOP_READOBJECTS = &H1& Private Const DESKTOP_WRITEOBJECTS = &H80& Private Const WM_CLOSE = &H10 Private Const WM_SYSCOMMAND = &H112 Public Function StopScreenSaverProc(ByVal hWnd As Long, lParam As Long) As Boolean Dim lngRet As Long Call PostMessage(hWnd, WM_CLOSE, 0, 0) Call SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 1, 0, SPIF_SENDWININICHANGE) StopScreenSaverProc = True End Function Public Sub StopScreenSaver() Dim OSVER As OSVERSIONINFO OSVER.dwOSVersionInfoSize = Len(OSVER) Call GetVersionEx(OSVER) Select Case OSVER.dwPlatformId Case VER_PLATFORM_WIN32_WINDOWS '95,98 Dim hWnd As Long hWnd = FindWindow("WindowsScreenSaverClass", vbNullString) If hWnd <> 0 Then Call PostMessage(hWnd, WM_CLOSE, 0, 0) End If Case VER_PLATFORM_WIN32_NT 'NT Dim hDesk As Long hDesk = OpenDesktop("Screen-Saver", 0, False, DESKTOP_READOBJECTS Or DESKTOP_WRITEOBJECTS) If hDesk <> 0 Then Call EnumDesktopWindows(hDesk, AddressOf StopScreenSaverProc, 0) Call CloseDesktop(hDesk) End If End Select End Sub