RestartDialog Function

Declare Function RestartDialog Lib "shell32.dll" Alias "#59" (ByVal hwndOwner As Long, ByVal lpstrReason As String, ByVal uFlags As Long) As Long

Platforms

The RestartDialog function is officially undocumented.

Description & Usage

RestartDialog prompts the user with a yes-or-no dialog box asking to either reboot, shut down, or log off the system. This dialog box is typically displayed at the end of an install routine, when a reboot is necessary to load altered system settings. If the user clicks the "Yes" button of the dialog, the reboot/shut down/log off operation is automatically begun.

Windows NT, 2000: All strings used by this function must be Unicode. Therefore, any strings passed to the function must first be converted into Unicode. Likewise, any strings output by the function also must be converted from Unicode into ANSI.

Return Value

If successful, the function returns one of the following values. However, if an error occured, the function will return IDYES anyway. Therefore, the return value is an unreliable method of determining what the user selected.

IDNO
The user selected "No".
IDYES
The user selected "Yes".

Visual Basic-Specific Issues

None.

Parameters

hwndOwner
A handle to the window that is requesting the dialog box.
lpstrReason
Text to display inside the dialog box explaining why the reboot, shut down, or log off is necessary. Windows will append additional text to this message, so this string should end in one or two carriage return/line feed pairs (the intrinsic vbCrLf constant) or at least a space.
uFlags
One of the following flags specifying which operation to prompt the user about:
EWX_LOGOFF
Prompt the user to log off the system. The text appended to lpstrReason is as follows: "You must restart your computer before the new settings will take effect. (new line) Do you want to restart your computer now?"
EWX_REBOOT
Prompt the user to reboot the system. The text appended to lpstrReason is as follows: "You must restart your computer before the new settings will take effect. (new line) Do you want to restart your computer now?"
EWX_SHUTDOWN
Prompt the user to shut the system down. The text appended to lpstrReason is as follows: "Do you want to shut down now?"

Constant Definitions

Const IDNO = 7
Const IDYES = 6
Const EWX_LOGOFF = &H0
Const EWX_SHUTDOWN = &H1
Const EWX_REBOOT = &H2

Example

' This code is licensed according to the terms and conditions listed here.

' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Declare Function RestartDialog Lib "shell32.dll" Alias "#59" (ByVal hwndOwner _
	As Long, ByVal lpstrReason As String, ByVal uFlags As Long) As Long
Public Const EWX_REBOOT = &H2
Public Type OSVERSIONINFO
	dwOSVersionInfoSize As Long
	dwMajorVersion As Long
	dwMinorVersion As Long
	dwBuildNumber As Long
	dwPlatformId As Long
	szCSDVersion As String * 128
End Type
Public Const VER_PLATFORM_WIN32_NT = 2
Public Const VER_PLATFORM_WIN32_WINDOWS = 1
Public Declare Function GetVersionEx Lib "kernel32.dll" Alias "GetVersionExA" _
	(lpVersionInformation As OSVERSIONINFO) As Long

' Prompt the user to reboot the computer.  If he says "Yes", the function will
' automatically reboot the system.  There's nothing much to it!
Private Sub Command1_Click()
	Dim s As String  ' the string to display in the dialog
	Dim ovi As OSVERSIONINFO  ' version of the OS
	Dim retval As Long  ' return value
	
	' Display the following message in the dialog, in front of the text that
	' Windows will automatically place there.
	s = "The install routine has made some changes to your computer.  "
	
	' If this is Windows NT or 2000, convert the string to Unicode.
	ovi.dwOSVersionInfoSize = Len(ovi)
	retval = GetVersionEx(ovi)
	If ovi.dwPlatformId = VER_PLATFORM_WIN32_NT Then
		s = StrConv(s, vbUnicode)
	End If
	
	' Prompt the user.
	retval = RestartDialog(Form1.hWnd, s, EWX_RESTART)
End Sub

See Also

ExitWindowsDialog

Category

Shell

Back to the Function list.
Back to the Reference section.


Last Modified: July 4, 2000
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/r/restartdialog.html