prevent a computer from going to sleep

I have a GPO in place that forces the monitor to sleep after 2 hours.  I was writing a small script to prevent this on a kiosk workstation.  I tried using sendkeys thinking it would simulate a keystroke, but that did not work.  Any ideas on a script that could keep the monitor from going to sleep without modifying the gpo?
chadmanvbAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vverduraCommented:
What if you change directly on Control Panel?
0
chadmanvbAuthor Commented:
I cant, the GPO greys out any power scheme changes.  I was hopping to have a small script setup as a schduled task to prevent this.  I thought haveing the sendkeys sent a shift command every hour would work, but it does not.
0
vverduraCommented:
I think the monitor only reacts (awake) to mouse or keyboard strokes. If so, try to use this app (http://movemouse.codeplex.com/) to "move" mouse even 1 px to simulate movement...
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

vverduraCommented:
you'll have a command prompt window in the taskbar...
0
chadmanvbAuthor Commented:
Well I just tried the script and it does not work.  Monitor still goes to sleep.  Since this is running in kiosk mode, windows explorer never starts so we dont have a task bar.  That application might work, but buying or even using freeware is not really an option.  I'll spend more time in paperwork trying to get it approved.  Any other ideas for a simple script?
0
vverduraCommented:
make an *.exe with Autohotkey (http://www.autohotkey.com/). You can make an "exe" and put it running in the pc and so you don't need to install nothing in that machine, only in yours...
0
vverduraCommented:
With AutoHotKey use this:

min = 5 ;Number of minutes to wait

loop {
    sleep, % min*60*1000
    mousemove, 10, 0, 20, R
    mousemove, -10, 0, 20, R
}

Open in new window

0
chadmanvbAuthor Commented:
I might try that, but I dont think it will work.  I just tried this to move the mouse thinking it would work
Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim MousePosX As Integer
        Dim MousePosY As Integer
        MousePosX = (Control.MousePosition.X - Me.Left)
        MousePosY = (Control.MousePosition.Y - Me.Top)
        Windows.Forms.Cursor.Position = New System.Drawing.Point(MousePosX + 1, MousePosY + 1)
       
    End Sub

I could see the mouse move every 10 seconds, but after a min, the screen would still shut off.

I also looked at this:

C:\Windows\System32\powercfg.exe -Change -monitor-timeout-ac 1

Doing that I get an error, like I dont have permisions, but I'm running it as an admin.
0
CodeCruiserCommented:
See if calling the following Windows API function makes it work

http://msdn.microsoft.com/en-us/library/aa373208.aspx
0
chadmanvbAuthor Commented:
Code, Do you know how I can do that in Visual basic .net?
0
CodeCruiserCommented:
Here


http://www.codeproject.com/Articles/290253/Give-your-computer-Sleep-Apnea-Dont-let-it-go-to-s


' API call to prevent sleep (until the application exits)
Private Declare Function uses the SetThreadExecutionState Lib _
        "kernel32" (ByVal esflags As EXECUTION_STATE) As EXECUTION_STATE

' Define the API execution states
Private Enum EXECUTION_STATE
    ' Stay in working state by resetting display idle timer
    ES_SYSTEM_REQUIRED = &H1
    ' Force display on by resetting system idle timer
    ES_DISPLAY_REQUIRED = &H2
    ' Force this state until next ES_CONTINUOUS call
    ' and one of the other flags are cleared
    ES_CONTINUOUS = &H80000000
End Enum

' Prevents sleep as form loads
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    No_Sleep()
End Sub

' Call API - force no sleep and no display turn off
Private Function No_Sleep() As EXECUTION_STATE
    Return SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED Or _
           EXECUTION_STATE.ES_CONTINUOUS Or EXECUTION_STATE.ES_DISPLAY_REQUIRED)
End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chadmanvbAuthor Commented:
That worked perfect only to give me another issue that I posted in another question.  If you have any ideas, let me know.
http://www.experts-exchange.com/Programming/Languages/.NET/Q_28274784.html

This is what I used and it works great.


Imports System.Runtime.InteropServices

Public Class Form1

    <DllImport("Kernel32.DLL", CharSet:=CharSet.Auto, SetLastError:=True)> _
    Private Shared Function SetThreadExecutionState(ByVal state As EXECUTION_STATE) As EXECUTION_STATE
    End Function


    ' API call to prevent sleep (until the application exits)
    Private Declare Function uses Lib "kernel32" (ByVal esflags As EXECUTION_STATE) As EXECUTION_STATE

    ' Define the API execution states
    Private Enum EXECUTION_STATE
        ' Stay in working state by resetting display idle timer
        ES_SYSTEM_REQUIRED = &H1
        ' Force display on by resetting system idle timer
        ES_DISPLAY_REQUIRED = &H2
        ' Force this state until next ES_CONTINUOUS call
        ' and one of the other flags are cleared
        ES_CONTINUOUS = &H80000000
    End Enum

    ' Prevents sleep as form loads
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        No_Sleep()
    End Sub

    ' Call API - force no sleep and no display turn off
    Private Function No_Sleep() As EXECUTION_STATE
        Return SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED Or _
               EXECUTION_STATE.ES_CONTINUOUS Or EXECUTION_STATE.ES_DISPLAY_REQUIRED)
    End Function
End Class
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.