阅读VBScript窗口以获得答案并执行批处理

时间:2014-07-21 21:14:16

标签: windows batch-file vbscript batch-processing

SETLOCAL ENABLEDELAYEDEXPANSION
curl "http://example.net/?u=%VARIABLE%" >> TXT.txt
wscript "C:\THAT.vbs" 
start "" "http://url.com/%VARIABLE%"
exit

我有(上面)批处理文件运行CURL并将输出写入txt文件。 此(下面)vbs文件读取内容并显示消息。 如您所见,我的批处理文件中有一个启动命令。 如果我在vbs窗口中单击是,我想执行该启动命令。 如果我在vbs窗口中单击No,我想退出。

Option Explicit
Const conForReading = 1
Dim objFSO, objReadFile, objFile, contents, result, shell, WshShell, somestring, txFldr2Open
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("TXT.txt") 

If objFile.Size > 0 Then 
Set objReadFile = objFSO.OpenTextFile("TXT.txt", 1, False)
contents = objReadFile.ReadAll
result = MsgBox ("HEADTEXT;" & vbCr & contents & "",vbYesNo+vbExclamation+vbSystemModal,"HEADQUESTION?")
Select Case result
Case vbYes
LET THE BATCH FILE KNOW ANSWER IS YES
Case vbNo
LET THE BATCH FILE KNOW ANSWER IS NO
End Select
objReadFile.close

Else 
End If  

Set objFSO = Nothing 
Set objReadFile = Nothing 
WScript.Quit() 

有可能吗?如果是这样的话?

1 个答案:

答案 0 :(得分:0)

使用vbscript中的退出代码将选择返回到批处理脚本

批处理文件

SETLOCAL ENABLEDELAYEDEXPANSION
curl "http://example.net/?u=%VARIABLE%" >> TXT.txt
cscript //nologo "C:\THAT.vbs" 
if not errorlevel 1 (
    start "" "http://url.com/%VARIABLE%"
)
exit

<强> that.vbs

Option Explicit
Const conForReading = 1
Dim objFSO, contents, result

    result = 1

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    If objFSO.GetFile("TXT.txt").Size > 0 Then 

        contents = objFSO.OpenTextFile("TXT.txt", 1, False).ReadAll

        If MsgBox ("HEADTEXT;" & vbCr & contents & "",vbYesNo+vbExclamation+vbSystemModal,"HEADQUESTION?") = vbYes Then
            result = 0
        End If 

    End If  

    WScript.Quit result