View: - 362
Option Explicit Private Declare Function SHRestartSystemMB Lib "shell32" Alias "#59" (ByVal hOwner As Long, ByVal sExtraPrompt As String, ByVal uFlags As Long) As Long Private Declare Function GetActiveWindow Lib "user32" () As Long 'Use Me.hwnd in VB Public Const EWX_LOGOFF = 0, EWX_SHUTDOWN = 1 Public Const EWX_REBOOT = 2, EWX_FORCE = 4, EWX_POWEROFF = 8 'Purpose : Gives the user the option to restarts the local machine ' showing the message box "System Settings Change", "You must ' restart your computer before the new settings will take effect." 'Inputs : [sExtraMessage] Any additional text you wish to show in the dialog ' [lMode] One of the EWX_ constants (See declarations) 'Outputs : Returns 7 is the user clicks No, else returns 0. 'Notes : If the User Clicks "Yes" the computer will restart. Function SystemUpdatedRestart(Optional ByVal sExtraMessage As String = vbNullString, Optional lMode As Long = EWX_REBOOT) As Long On Error Resume Next If Len(sExtraMessage) Then 'Format and convert extra message If Right$(sExtraMessage, 2) <> vbNewLine Then sExtraMessage = sExtraMessage & vbNewLine & vbNewLine End If sExtraMessage = StrConv(sExtraMessage, vbUnicode) End If SystemUpdatedRestart = SHRestartSystemMB(GetActiveWindow, sExtraMessage, EWX_FORCE) On Error GoTo 0 End Function