Click here to Skip to main content
Click here to Skip to main content

Tagged as

Disable Screensaver

, 13 Nov 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
Disables the screensaver even on machines where it's not allowed due to domain policy.

 

Introduction

In many workplaces, the domain policy will not allow you to disable your screensaver. Often it's not even possible to adjust the time before the screensaver sets in. When the screensaver starts, you will have to login to the workstation again using ctrl+alt+del and then enter domain credentials.

 

When using multiple workstations, both physical and virtual, this process can be very time consuming and annoying during the work day, if you e.g. have to login to different machines every third minute.

Disable Screensaver is a small light utility that runs in the background and makes sure that the screensaver will not be activated automatically.

Disable Screensaver does not require any installation. Just place the standalone executable DisableScreensaver.exe in a directory and run it.

Background

Disable Screensaver will query the default domain screensaver timeout value. Then behind the scenes, it will press the "Scroll Lock" button twice a second before the screensaver will start. This will reset the screensaver timeout value, and not in any way interfere with your workflow.

 

Using the Code

To be able to programatically press the "Scroll Lock" button, PInvoke is used:

 
        [DllImport("user32.dll")]
        static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
 
		private static void PressScrollLock()
        {
            const byte vkScroll = 0x91;
            const byte keyeventfKeyup = 0x2;
 
            keybd_event(vkScroll, 0x45, 0, (UIntPtr)0);
            keybd_event(vkScroll, 0x45, keyeventfKeyup, (UIntPtr)0);
        }
 

PInvoke is also used to query the domain policy for the sceensaver timout:

 
        [DllImport("user32.dll")]
        private static extern bool SystemParametersInfo(int uAction, int uParam, ref int lpvParam, int flags);
		
        public static Int32 GetScreenSaverTimeout()
        {
            Int32 value = 0;
            SystemParametersInfo(14, 0, ref value, 0);
            return value;
        }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

No Biography provided

Comments and Discussions

 
Generalso it doesnt disable screensaver, it just keeps it on wait T... PinmemberJFergulbops8-Nov-10 23:33 
GeneralThanks For Sharing PinmemberRobert Cowan15-Nov-10 23:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 13 Nov 2010
Article Copyright 2010 by Lars Hove Christiansen
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid