Question 4

Comment quitter ou redémarrer Windows ?

Il faut employer l'API ExitWindowsEx :

Option Explicit
 
Const EWX_LOGOFF   As Long = 0
Const EWX_SHUTDOWN As Long = 1
Const EWX_REBOOT   As Long = 2

Public Declare Function ExitWindowsEx Lib "user32" ( _
                       ByVal uFlags As Long, _
                       ByVal dwReserved As Long) As Long

' Exemple d'appel
'
Sub Main()

    If MsgBox("Voulez-vous fermer Windows ?", vbQuestion + vbYesNo) = vbYes Then
        ExitWindowsEx EWX_SHUTDOWN, 0
    End If
    
End Sub

Remarque : Sous Windows NT, 2000 et XP, il faut bénéficier du privilège SE_SHUTDOWN_NAME pour pouvoir employer cette API.

Pour aller plus loin

Voir aussi :

Date de publication : 07 juillet 2002
Dernière modification : 06 mars 2008
Rubriques : Windows
Mots-clés : quitter, redémarrer, fermer, ExitWindowsEx, shutdown, logoff, reboot