Comment mettre l'ordinateur en veille depuis un programme VB ?
Pour mettre l'ordinateur en veille ou en veille prolongée, il suffit d'utiliser la fonction SetSuspendState de l'API Windows. Voici un exemple tout simple de mise en oeuvre : Private Declare Function SetSuspendState Lib "Powrprof.dll" ( _ ByVal Hibernate As Long, _ ByVal ForceCritical As Long, _ ByVal DisableWakeEvents As Long _ ) As Long
Private Function SystemSuspend() As Long
SystemSuspend = SetSuspendState(0, 1, 0)
End Function
Private Function SystemHibernate() As Long SystemHibernate = SetSuspendState(1, 1, 0) End Function
Private Sub Command1_Click() Dim lRet As Long lRet = SystemHibernate() If lRet <> 0 Then End If End Sub
Il est possible d'appeler cette API en utilisant la fonction Shell en conjonction avec rundll32 : Private Sub SystemSuspend()
Shell "rundll32.exe powrprof.dll,SetSuspendState 0,1,0" End Sub
Pour aller plus loin Voir aussi : |