Declare Function RestartDialog Lib "shell32.dll" Alias "#59" (ByVal hwndOwner As Long, ByVal lpstrReason As String, ByVal uFlags As Long) As Long
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.
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.
None.
Const IDNO = 7
Const IDYES = 6
Const EWX_LOGOFF = &H0
Const EWX_SHUTDOWN = &H1
Const EWX_REBOOT = &H2
' 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
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