Questa procedura consente di riavviare Windows. Funziona con Windows 3.1x, Windows 9x, NT.
Option Explicit
‘Determina se trattasi di una piattaforma a 16 o 32 bit
#If Win32 Then
Private Declare Function ShutdownWindows Lib “user32” Alias _
“ExitWindowsEx” (ByVal uFlags As Long, _
ByVal dwReserved As Long) As Long
#Else
Private Declare Function ShutdownWindows Lib “user” Alias _
“ExitWindows” (ByVal wReturnCode As Integer, _
ByVal dwReserved As Integer) As Integer
#End If
Private Const EWX_LOGOFF = 0
Private Const EWX_SHUTDOWN = 1
Private Const EWX_REBOOT = 2
Private Const EWX_FORCE = 4
‘unica subroutine da usare (va associata all’evento Click di un command button)
Sub cmdRestart_Click ()
Dim x As Integer
Dim Response As Variant
Response = MsgBox(“Questa procedura riavvierà Windows.” & _
vbCrLf & “Attenzione!”, vbYesNo + vbQuestion, _
“Riavviare Windows?”)
If Response = vbYes Then
‘Riavvia Windows
x = ShutdownWindows(EWX_REBOOT, 0)
If Not x Then
Response = MsgBox(“Uno o più programmi non possono essere chiusi”, _
vbExclamation, “Impossibile riavviare Windows”)
End If
End If
End Sub