elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a la Factorización De Semiprimos (RSA)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Evitar bloqueo windows 7
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Evitar bloqueo windows 7  (Leído 1,868 veces)
Amaro

Desconectado Desconectado

Mensajes: 5


Ver Perfil
Evitar bloqueo windows 7
« en: 19 Enero 2016, 09:51 am »

Buenas, pues os comento, tengo el siguiente problema y es que tengo una aplicación muy simple para que mueva, con un timer, la posición del ratón. Esta funciona perfectamente en windows xp (ya esta probada) pero en windows 7 no entiendo porqué no funciona. Así que la pregunta es si alguien ha hecho al similar que evite el bloqueo/suspensión del pc.

Un saludo y gracias de antemano.


En línea

Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.818



Ver Perfil
Re: Evitar bloqueo windows 7
« Respuesta #1 en: 26 Enero 2016, 16:47 pm »

Para evitar la suspensión/bloqueo del equipo puedes utilizar la función SetThreadExecutionState de la WinAPI con la que debes enviar una señal cada cierto tiempo para mentenerlo "despierto".


No puedo ayudarte mucho mostrándote código en Vb6, pero de todas formas creo que estos ejemplos en VB.Net te ayudarán, con lo que encuentres por ti mismo en Google sobre el uso de dicha función en VB6...

P/Invokes:
Código
  1.        ''' ----------------------------------------------------------------------------------------------------
  2.        ''' <summary>
  3.        ''' Enables an application to inform the system that it is in use,
  4.        ''' thereby preventing the system from entering sleep or turning off the display while the application is running.
  5.        ''' </summary>
  6.        ''' ----------------------------------------------------------------------------------------------------
  7.        ''' <remarks>
  8.        ''' <see href="http://msdn.microsoft.com/es-es/library/windows/desktop/aa373208%28v=vs.85%29.aspx"/>
  9.        ''' </remarks>
  10.        ''' ----------------------------------------------------------------------------------------------------
  11.        ''' <param name="esFlags">
  12.        ''' The thread's execution requirements.
  13.        ''' <para></para>
  14.        ''' This parameter can be one or more of the <see cref="ExecutionState"/> values.
  15.        ''' </param>
  16.        ''' ----------------------------------------------------------------------------------------------------
  17.        ''' <returns>
  18.        ''' If the function succeeds, the return value is the previous thread's <see cref="ExecutionState"/> value.
  19.        ''' <para></para>
  20.        ''' If the function fails, the return value is <see langword="Nothing"/>.
  21.        ''' </returns>
  22.        ''' ----------------------------------------------------------------------------------------------------
  23.        <DllImport("kernel32.dll", SetLastError:=True)>
  24.        Public Shared Function SetThreadExecutionState(ByVal esFlags As ExecutionState
  25.        ) As ExecutionState
  26.        End Function

Enumeraciones:
Código
  1.    ''' ----------------------------------------------------------------------------------------------------
  2.    ''' <summary>
  3.    ''' Enables an application to inform the system that it is in use,
  4.    ''' thereby preventing the system from entering sleep or turning off the display while the application is running.
  5.    ''' </summary>
  6.    ''' ----------------------------------------------------------------------------------------------------
  7.    ''' <remarks>
  8.    ''' <see href="http://msdn.microsoft.com/es-es/library/windows/desktop/aa373208%28v=vs.85%29.aspx"/>
  9.    ''' </remarks>
  10.    ''' ----------------------------------------------------------------------------------------------------
  11.    <Flags>
  12.    Public Enum ExecutionState As UInteger
  13.  
  14.        ''' <summary>
  15.        ''' Any state.
  16.        ''' <para></para>
  17.        ''' Don't use this value.
  18.        ''' This value is used to detect a <see cref="ExecutionState"/> function fail.
  19.        ''' </summary>
  20.        None = &H0UI
  21.  
  22.        ''' <summary>
  23.        ''' Enables away mode.
  24.        ''' This value must be specified with <see cref="ExecutionState.Continuous"/>.
  25.        ''' <para></para>
  26.        ''' Away mode should be used only by media-recording and media-distribution applications that must
  27.        ''' perform critical background processing on desktop computers while the computer appears to be sleeping.
  28.        ''' <para></para>
  29.        ''' Windows Server 2003: <see cref="ExecutionState.AwaymodeRequired"/> is not supported.
  30.        ''' </summary>
  31.        AwaymodeRequired = &H40UI
  32.  
  33.        ''' <summary>
  34.        ''' Informs the system that the state being set should remain in effect until the
  35.        ''' next call that uses <see cref="ExecutionState.Continuous"/> and one of the other <see cref="ExecutionState"/> flags is cleared.
  36.        ''' </summary>
  37.        Continuous = &H80000000UI
  38.  
  39.        ''' <summary>
  40.        ''' Forces the display to be on by resetting the display idle timer.
  41.        ''' <para></para>
  42.        ''' Windows 8: This flag can only keep a display turned on, it can't turn on a display that's currently off.
  43.        ''' </summary>
  44.        DisplayRequired = &H2UI
  45.  
  46.        ''' <summary>
  47.        ''' Forces the system to be in the working state by resetting the system idle timer.
  48.        ''' </summary>
  49.        SystemRequired = &H1UI
  50.  
  51.        ''' <summary>
  52.        ''' This value is not supported.
  53.        ''' <para></para>
  54.        ''' If <see cref="ExecutionState.UserPresent"/> is combined with other <see cref="ExecutionState"/> values,
  55.        ''' the call will fail and none of the specified states will be set.
  56.        ''' </summary>
  57.        UserPresent = &H4UI
  58.  
  59.    End Enum

A la función deberías pasarle los siguientes flags como te muestro en este ejemplo que escribí para Visual Basic.Net:
Código
  1. ''' ----------------------------------------------------------------------------------------------------
  2. ''' <summary>
  3. ''' Sends an Awake signal to prevent the system from turning off the display and entering into Sleep or Hibernation modes.
  4. ''' </summary>
  5. ''' ----------------------------------------------------------------------------------------------------
  6. ''' <remarks>
  7. ''' The Awake signal should be sent periodically.
  8. ''' </remarks>
  9. ''' ----------------------------------------------------------------------------------------------------
  10. ''' <returns>
  11. ''' <see langword="True"/> if operation succeeds, <see langword="False"/>  otherwise.
  12. ''' </returns>
  13. ''' ----------------------------------------------------------------------------------------------------
  14. ''' <exception cref="Win32Exception">
  15. ''' </exception>
  16. ''' ----------------------------------------------------------------------------------------------------
  17. <DebuggerStepThrough>
  18. Public Shared Function SendAwakeSignal() As Boolean
  19.  
  20.    Dim result As ExecutionState = ExecutionState.None
  21.    Dim win32Err As Integer
  22.  
  23.    result = NativeMethods.SetThreadExecutionState(ExecutionState.Continuous Or
  24.                                                   ExecutionState.SystemRequired Or
  25.                                                   ExecutionState.DisplayRequired Or
  26.                                                   ExecutionState.AwaymodeRequired)
  27.  
  28.    win32Err = Marshal.GetLastWin32Error
  29.  
  30.    If (result = ExecutionState.None) Then
  31.        Throw New Win32Exception([error]:=win32Err)
  32.  
  33.    Else
  34.        Return True
  35.  
  36.    End If
  37.  
  38. End Function

Ten en cuenta que volver a permitir la suspensión es responsabilidad tuya, y lo harías llamando a la misma función Win32.
Ejemplo, en Vb.Net:
Código
  1. ''' ----------------------------------------------------------------------------------------------------
  2. ''' <summary>
  3. ''' Removes any previouslly sent Awake signal.
  4. ''' <para></para>
  5. ''' Call this function to return to previous state when the caller thread has finished.
  6. ''' </summary>
  7. ''' ----------------------------------------------------------------------------------------------------
  8. ''' <returns>
  9. ''' <see langword="True"/> if operation succeeds, <see langword="False"/>  otherwise.
  10. ''' </returns>
  11. ''' ----------------------------------------------------------------------------------------------------
  12. ''' <exception cref="Win32Exception">
  13. ''' </exception>
  14. ''' ----------------------------------------------------------------------------------------------------
  15. <DebuggerStepThrough>
  16. Public Shared Function RemoveAwakeSignal() As Boolean
  17.  
  18.    Dim result As ExecutionState = ExecutionState.None
  19.    Dim win32Err As Integer
  20.  
  21.    result = NativeMethods.SetThreadExecutionState(ExecutionState.Continuous)
  22.    win32Err = Marshal.GetLastWin32Error
  23.  
  24.    If (result = ExecutionState.None) Then
  25.        Throw New Win32Exception([error]:=win32Err)
  26.  
  27.    Else
  28.        Return True
  29.  
  30.    End If
  31.  
  32. End Function

Un ejemplo de uso de ambas funciones, en Vb.Net:
Código
  1. Public Class Form1 : Inherits Form
  2.  
  3.     Private WithEvents awakeTimer As Threading.Timer
  4.     Private ReadOnly awakeInterval As Integer = 30000 'ms
  5.  
  6.     Public Sub New()
  7.  
  8.         Me.InitializeComponent()
  9.         Me.awakeTimer = New Threading.Timer(AddressOf Me.AwakeTimer_Callback, Nothing, Me.awakeInterval, 0)
  10.  
  11.     End Sub
  12.  
  13.     Private Sub AwakeTimer_Callback(ByVal stateInfo As Object)
  14.  
  15.         ' Send periodically an Awake signal to avoid the system entering into Sleep or Hibernation mode.
  16.         Power.SendAwakeSignal()
  17.  
  18.         If (Me.awakeTimer IsNot Nothing) Then
  19.             Me.awakeTimer.Change(Me.awakeInterval, 0)
  20.         End If
  21.  
  22.     End Sub
  23.  
  24.     Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) _
  25.     Handles MyBase.FormClosing
  26.  
  27.         Me.awakeTimer.Dispose()
  28.         Me.awakeTimer = Nothing
  29.         Power.RemovedAwakeSignal()
  30.  
  31.     End Sub
  32.  
  33. End Class

Los códigos los saqué de mi API ElektroKit:



Saludos


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
duda debian evitar bloqueo de pantalla
GNU/Linux
.:UND3R:. 0 3,105 Último mensaje 8 Mayo 2011, 22:53 pm
por .:UND3R:.
The Pirate Bay cambia de dominio para evitar su bloqueo
Noticias
wolfbcn 1 2,208 Último mensaje 9 Abril 2013, 16:27 pm
por ShadowMyst
Tema difícil: Evitar bloqueo DNS al usar WebBrowser « 1 2 »
Programación Visual Basic
okik 11 5,119 Último mensaje 9 Abril 2015, 16:45 pm
por Pablo Videla
Evitar bloqueo DNS
Redes
okik 0 1,634 Último mensaje 8 Abril 2015, 14:08 pm
por okik
Cómo evitar pasar por la pantalla de bloqueo al iniciar Windows 10
Noticias
wolfbcn 0 1,086 Último mensaje 22 Octubre 2015, 21:23 pm
por wolfbcn
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines