Shutdown pc - extinction du pc en fonction de l'heure

Description

Voila j'avais besoin d'un petit soft qui me permet de programmer l'heure de fermeture du pc, car quand je regarde la tv avec ma wintv , je tombe souvent dans les bras de morphé!!! et le lendemain le pc a tourné toute la nuit, sans compter que ca me reveille aussi parfois lol....

C'est un code tous simple qui permet de selectionner l'heure de fermeture de windows, avec une petite option de confirmation. Une fentre s'ouvre avec un compte a rebours de 10sec qui permet soit d'annuler la fermeture , ou de la valider avant les 10 sec!!!

J'espére que ça servira a qq!!!

Source / Exemple :


' Dans form1
'----------------
'Declaration des variables
Dim Pas As Integer 'avancement Minute
Dim Extinction As Boolean 'Activation?

Private Sub Form_Load()
    'Definition des variables
    Pas = 1
    Extinction = False
    'Affichage
    Label1 = Time
    LblStatus = "Désactivé..."
    Lblh = Format(Hour(Time), "00")
    Lblm = Format(Minute(Time), "00")
End Sub

'===================================================
' Bouton ajout et suppression Heures/minutes
'===================================================

Private Sub Command1_Click()
    'Ajout heure
    Lblh = Lblh + 1
    If Lblh = 24 Then Lblh = 0
    Lblh = Format(Lblh, "00")
End Sub

Private Sub Command4_Click()
'Soustrait heure
    Lblh = Lblh - 1
    If Lblh = -1 Then Lblh = 23
    Lblh = Format(Lblh, "00")
End Sub

Private Sub Command2_Click()
    'Ajout Minute selon pas
    Lblm = (Lblm + Pas) Mod 60
    Lblm = Format(Lblm, "00")
End Sub

Private Sub Command3_Click()
    'Soustrait Minute selon pas
    If Lblm > Pas Then Lblm = (Lblm - Pas) Mod 60 Else Lblm = 60 - (Pas - Lblm)
    Lblm = Format(Lblm, "00")
End Sub

'===================================================
' Activation/desactivation
'===================================================
Public Sub Check1_Click()
    'Activation/desactivation
    If Check1.Value = 1 Then Extinction = True: Timer1.Enabled = True Else Extinction = False: Me.Caption = "Shutdown Pc"
End Sub

'===================================================
' Definition du pas
'===================================================

Private Sub Option1_Click(Index As Integer)
Pas = Option1(Index).Caption
End Sub

'=======================================================
' Affichage heure et comparaison de l'heure d'extinction
'=======================================================
Private Sub Timer1_Timer()
Label1 = Time

If Extinction Then
    'verification
    If Format(Hour(Time), "00") = Lblh And Format(Minute(Time), "00") = Lblm Then
        'confirmation
        If Check2.Value = 1 Then Form2.Show Else Timer1.Enabled = False: Call Shutdown
    End If
End If

If Me.WindowState = vbMinimized Then 'si minimiser

    If Format(Hour(Time), "00") <> Lblh Then
        Me.Caption = "Shutdown " & Lblh & ":" & Lblm
    Else
        Me.Caption = "Shutdown :" & Lblm - Hour(Time) & " min"
    End If
End If
End Sub

'==============================================================
' Procedure pour forcer l'extinction de windows (Testé sous XP)
'==============================================================
Public Sub Shutdown()
Shell "shutdown -s -t 0"
End
End Sub

'Dans form2
'--------------
Dim Sec As Integer

Private Sub Command1_Click()
Form1.Shutdown: Unload Me
End Sub

Private Sub Command2_Click()
Form1.Check1.Value = 0
Form1.Check1_Click: Unload Me
End Sub

Private Sub Form_Load()

Sec = 0
End Sub

Private Sub Timer1_Timer()
Sec = Sec + 1
Command1.Caption = "OK (" & (10 - Sec) & ")"
If Sec = 10 Then Form1.Shutdown: Unload Me
End Sub

Conclusion :


Ps: pour forcer la fermeture de windows j'utilise un simple : Shell "shutdown -s -t 0"
Testé sous win xp Ef et Pro, pas de probléme apparent pour les autres os???? a vous de le dire!!

++

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.