我需要帮助使用VBScript来控制命令行程序

时间:2014-06-20 17:19:20

标签: windows batch-file vbscript

使用VBScript(仅举例)

result = MsgBox ("Would you like to install the AntrixAPI?", vbYesNo, "Installing AntrixAPI")

Select Case result
Case vbYes
MsgBox("The API will be installed.")
Case vbNo
MsgBox("The API will not be install.")
End Select

我如何使用它来控制命令行程序。假设用户选择了是。然后,只有当用户选择是时,命令才会到达某一点。 (示例命令)

@echo off
:UserSelectedYes
REM This is where the prompt would go if the user selected yes
wget http://www.example.com/thisisafakedomain/api/antrix
:UserSelectedNo
REM This is where the prompt would go if the user selected no
end

这可能吗?

3 个答案:

答案 0 :(得分:0)

您可以创建一个MS-DOS进程并执行您想要的每个脚本!

就像这样:

Dim oProcess As New Process
With (oProcess.StartInfo)
   .Arguments = "/k <command> & <command> & <command> & exit"
    .FileName = "cmd.exe"
    .WindowStyle = ProcessWindowStyle.Hidden
    .CreateNoWindow = True
End With
oProcess.Start()

这不是最好和最绅士的方式,但速度最快。 我不确切地知道,如果这是你想要的。所以你可以随意重新定义你的问题,你要求的内容不是很清楚!

答案 1 :(得分:0)

您的VBScript可以像这样简单:

WScript.Quit MsgBox("Would you like to install the AntrixAPI?", vbYesNo, "Installing AntrixAPI")

从批处理文件中调用它并测试返回值。 vbYes的值为6,vbNo的值为7.

@echo off
cscript c:\test.vbs

if %errorlevel%==6 goto UserSelectedYes
if %errorlevel%==7 goto UserSelectedNo

答案 2 :(得分:0)

这是如何在vbscript中下载文件。

 On Error Resume Next
 Set File = WScript.CreateObject("Microsoft.XMLHTTP")
 File.Open "GET", "http://www.pepperresources.org/LinkClick.aspx?fileticket=B1doLYYSaeY=&tabid=61", False
 'This is IE 8 headers
 File.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C; .NET4.0E; BCD2000; BCD2000)"
 File.Send
 If err.number <> 0 then 
    line =""
    Line  = Line &  vbcrlf & "" 
    Line  = Line &  vbcrlf & "Error getting file" 
    Line  = Line &  vbcrlf & "==================" 
    Line  = Line &  vbcrlf & "" 
    Line  = Line &  vbcrlf & "Error " & err.number & "(0x" & hex(err.number) & ") " & err.description 
    Line  = Line &  vbcrlf & "Source " & err.source 
    Line  = Line &  vbcrlf & "" 
    Line  = Line &  vbcrlf & "HTTP Error " & File.Status & " " & File.StatusText
    Line  = Line &  vbcrlf &  File.getAllResponseHeaders
    wscript.echo Line
    Err.clear
    wscript.quit
 End If

On Error Goto 0

 Set BS = CreateObject("ADODB.Stream")
 BS.type = 1
 BS.open
 BS.Write File.ResponseBody
 BS.SaveToFile "c:\users\test.txt", 2