VB and VBA Users Source Code: Show the "System Settings Changed, Restart Computer?" dialog
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Show the "System Settings Changed, Restart Computer?" dialog
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Monday, March 05, 2001
Hits:
687
Category:
Windows API
Article:
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. 'Author : Andrew Baker 'Date : 14/01/2001 12:20 'Notes : If the User Clicks "Yes" the computer will restart. 'Revisions : 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
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder