Visual Basic > Windows and Controls
Show the 'System Settings Changed, Restart Computer' dialog
Show the 'System Settings Changed, Restart Computer' dialog Often at the end of a setup process the user will be prompted if they want to restart the computer. The following function uses an unsupported MS API to display this dialog. If the user clicks yes to this dialog the machine will restart. 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
Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows