Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding vbs yes/no box code to a batch file

I am trying to add the following yes/no box into a batch file but keep failing.

Set objShell = CreateObject("Wscript.Shell")

intMessage = Msgbox("Would you like to go to URL?", _
    vbYesNo, "Click yes to go to URL")

If intMessage = vbYes Then
    objShell.Run("http://www.url.com")
Else
    Wscript.Quit
End If

Can anyone point me in the right direction please?

like image 867
DaE Avatar asked Mar 31 '26 05:03

DaE


1 Answers

@echo off

    call :MsgBox "Would you like to go to URL?"  "VBYesNo+VBQuestion" "Click yes to go to URL"
    if errorlevel 7 (
        echo NO - don't go to the url
    ) else if errorlevel 6 (
        echo YES - go to the url
        start "" "http://www.google.com"
    )

    exit /b

:MsgBox prompt type title
    setlocal enableextensions
    set "tempFile=%temp%\%~nx0.%random%%random%%random%vbs.tmp"
    >"%tempFile%" echo(WScript.Quit msgBox("%~1",%~2,"%~3") & cscript //nologo //e:vbscript "%tempFile%"
    set "exitCode=%errorlevel%" & del "%tempFile%" >nul 2>nul
    endlocal & exit /b %exitCode%
like image 166
MC ND Avatar answered Apr 03 '26 05:04

MC ND