Results 1 to 13 of 13

Thread: Stopping screensaver via code

  1. #1

    Thread Starter
    Addicted Member Guru's Avatar
    Join Date
    May 2000
    Location
    sulking in the cupboard under the stairs
    Posts
    237

    Stopping screensaver via code

    I need to be able to unload the screensaver via code
    ie. same as moving the mouse or pressing a key

    Any ideas?


    Thanks
    Another light-hearted post from Guru

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Stopping screensaver via code

    Is the screensave password protected?

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Stopping screensaver via code

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Stopping screensaver via code

    Quote Originally Posted by RobDog888
    Yes, it will help , providing there is no screensaver password.

  5. #5
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Stopping screensaver via code

    Couldn't you just do something like :

    VB Code:
    1. SendKeys "{ENTER}"

    ?


    Has someone helped you? Then you can Rate their helpful post.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Stopping screensaver via code

    Quote Originally Posted by manavo11
    Couldn't you just do something like :

    VB Code:
    1. SendKeys "{ENTER}"

    ?
    Not if it has a password.

  7. #7
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: Stopping screensaver via code

    Sorry for the thread hijack, but how can you prevent the screensaver from ever coming up (using code)?

    For example, simply send a message of some sort every 14 minutes to Windows that represents a user input.

    Thanks!

    Dave
    Last edited by Dave Sell; Jan 23rd, 2006 at 10:16 AM.
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  8. #8
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Stopping screensaver via code

    Quote Originally Posted by Dave Sell
    Sorry for the thread hijack, but how can you prevent the screensaver from ever coming up (using code)?
    For example, simply send a message of some sort every 14 minutes to Windows that represents a user input.
    Thanks!
    Dave
    VB Code:
    1. Private Declare Function SystemParametersInfo Lib "user32" Alias _
    2.            "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, _
    3.            ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long
    4. Const SPI_SETSCREENSAVEACTIVE = 17
    5. Dim rtn As Long
    To deactivate:
    VB Code:
    1. rtn = SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, False, ByVal 0&, 0)
    To activate again
    VB Code:
    1. rtn = SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, True, ByVal 0&, 0)
    If succeds, return a value <> 0.
    - Be sure to activate it again when you close your program, else it will remain inactive.
    - I don't know if this works with password protected screensavers.

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Stopping screensaver via code

    Doesnt matter if there is a password. This wil disable the screensaverfrom running. It will work even if they manually go in and set the screensaver again.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, _
    4. ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
    5.  
    6. Private Const SPI_GETSCREENSAVETIMEOUT As Long = 14
    7. Private Const SPI_SETSCREENSAVETIMEOUT As Long = 15
    8. Private Const SPI_GETSCREENSAVEACTIVE As Long = 16
    9. Private Const SPI_SETSCREENSAVEACTIVE As Long = 17
    10.  
    11. Private Const SPIF_UPDATEINIFILE = &H1
    12. Private Const SPIF_SENDWININICHANGE As Long = &H2
    13.  
    14. Private Sub Timer1_Timer()
    15.     Dim lRet As Long
    16.     Dim iDuration As Integer
    17.     Dim bActive As Boolean
    18.     SystemParametersInfo SPI_GETSCREENSAVEACTIVE, 0&, bActive, False
    19.     If bActive <> 0 Then
    20.         lRet = SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0&, Null, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
    21.         If lRet <> 0 Then
    22.             Debug.Print "Stoped: " & lRet
    23.             'Change duration to 9999 Minutes
    24.             SystemParametersInfo SPI_SETSCREENSAVETIMEOUT, 599940, Null, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE
    25.             'Timer1.Enabled = False
    26.         End If
    27.     Else
    28.         Debug.Print "Not Running: " & bActive
    29.     End If
    30. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: Stopping screensaver via code

    Disabling the screensaver is not the answer and not what I asked for. I want to "fool" the system into thinking there is user input every 14 minutes. No other solution will suffice.

    To repeat: how do I fake some user input in order to prevent the screensaver from kicking in?
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Stopping screensaver via code

    Thats what you get for hijacking the thread :Lol: Jk.

    Wouldnt moving the mouse using the POINTAPI Type and some APIs do the trick? If not maybe use the Keybd_event API to send a Shift keypress or move the mouse would suffice?


    My changing the duration was not amusing? You could just change it back after your program is done or loses?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: Stopping screensaver via code

    Any attempt to change the configuration is basically illegal due to overly oppressive network policies. However I thought I could skirt the issue by faking user input. I thought I might bundle this up into a utility.
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  13. #13
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Stopping screensaver via code

    Quote Originally Posted by Dave Sell
    Any attempt to change the configuration is basically illegal due to overly oppressive network policies. However I thought I could skirt the issue by faking user input. I thought I might bundle this up into a utility.
    What about sending just a little mouse movement with Mouse_Event, in a timer?
    But that should be done just after certain time without user input.

    EDIT: Oh, i just see now RD post, sorry
    Last edited by jcis; Jan 24th, 2006 at 09:11 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width