Q. How can I use a script to display a Yes/No confirmation box?
John Savill
June 17, 2004
1 Min Read
A. You can use the Msgbox function to display a Yes/No dialog box, as the following example shows:
Ret=Msgbox("Are you sure you want to reboot?",VBYesNo,"Reboot Confirm")
Ret is variable that contains the Msgbox return code, which varies depending on the button the user pressed (Yes returns a value of 6; No returns a value of 7). The parentheses contain the question text; the VBYesNo constant, which tells VBScript to display Yes and No buttons; and the dialog box title. The figure at Figure shows the Yes/No box that the code example produces.
The following code shows how to use the Msgbox function in a script:
Ret=Msgbox_("Are you sure you want to reboot?",VBYesNo,"Reboot confirm")If Ret=6 then Set OpSysSet =GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery_("select * from Win32_OperatingSystem where Primary=true") for each OpSys in OpSysSet OpSys.Reboot() nextend if
(The Ret=Msgbox and GetObject lines each wrap to two lines here because of space constraints.) You can download the Msgbox code example at Code.
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like