Page 1 of 1

Batch Script to Refresh screen?

Posted: 06 May 2010 08:58
by burnleylad_84
Is it possible to make a Batch Script that remains open but minimised that will either automate F5 to refresh my screen or will move my mouse or something every 2.5 minutes using the ping command, this is to avoid my work computer locking after 5 minutes of idle time.

Thanks,

Re: Batch Script to Refresh screen?

Posted: 06 May 2010 10:23
by jeb
Hi burnleylad_84,

I assume that it is not possible with pure dos.

But I know how to solve it with C#, it's a simple api call.
Perhaps you can call it from vbscript also ( I don't use vbs at all ).

Code: Select all

    public static class SleepPreventer
    {
        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        static extern EXECUTION_STATE SetThreadExecutionState(
            EXECUTION_STATE flags);

        [Flags]
        public enum EXECUTION_STATE : uint
        {
            ES_SYSTEM_REQUIRED = 0x00000001,
            ES_DISPLAY_REQUIRED = 0x00000002,
            // ES_USER_PRESENT = 0x00000004,
            ES_CONTINUOUS = 0x80000000
        }

        static public void ResetIdleTimer()
        {
            SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED);
        }
    }


jeb

Re: Batch Script to Refresh screen?

Posted: 06 May 2010 11:28
by burnleylad_84
I think you can invoke F5 (Refresh Key) in Batch and then use ping to set up on an interval and just use echo to loop so its continual and does not close.

I know c++ but thought of something more simple as its for work.

Re: Batch Script to Refresh screen?

Posted: 06 May 2010 11:44
by jeb
You are right, you can invoke the key, but (I suppose) it doesn't help,
because it will not reset the windows idle timer.

But perhaps you can use the shutdown to reset the timer

Something like
shutdown /...
and then cancel it with
shutdown /a

Re: Batch Script to Refresh screen?

Posted: 06 May 2010 12:03
by burnleylad_84
I'll do a small app then in c++ and hook the mouse onto an area of the screen and move the cursor every 2.5 minutes or something, should be pretty straight forward.

thx

Re: Batch Script to Refresh screen?

Posted: 06 May 2010 13:01
by jeb
Hmm I doesn't understand why you will solve it that way?

If you write a c++ programm which only calls the api

Code: Select all

#define ES_SYSTEM_REQUIRED 1UL
void main()
{
SetThreadExecutionState(ES_SYSTEM_REQUIRED);
}


you can start that program with your ping method