从VBscript执行多个批处理文件

时间:2017-12-02 14:39:23

标签: vbscript

我正在尝试使用vbscript在文件夹中执行多个批处理文件。任何人都可以帮助我如何做到这一点。 这是我的代码。

 Varr1 = hostname
 UN = username
 password = pass
set ObjFSO = createobject("Scripting.FileSystemObject")
     set FilePath = ObjFSO.getfolder("C:\test\script")
     set BatFile = FilePath.files

     for each m in BatFile
      If LCase(objFSO.GetExtension(FilePath.files)) = "bat" Then
         Set WShell = CreateObject("WScript.Shell")
         WShell.Run ("CMD /K C:\test\script "&BatFile &" " & Varr1 &" "& UN &" "& password )
      End If
    Next

1 个答案:

答案 0 :(得分:0)

给出.BAT文件,如:

@echo off
echo a, $1, $2

在当前目录中,.VBS如:

Option Explicit

Const u = "user"
Const p = "passw"

Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject")
Dim goWS : Set goWS = CreateObject("WScript.Shell")
Dim f, c
For Each f In goFS.GetFolder(".\").Files 
    If "bat" = goFS.GetExtensionName(f.Name) Then
        c = Join(Array("%comspec%", "/K", f.Name, u, p)) 
        WScript.Echo "will call", c
        goWS.Run c
    End If
Next

将在新游戏机中执行所有这些操作。

输出:

cscript 47609016.vbs
will call %comspec% /K b.bat user passw
will call %comspec% /K a.bat user passw

(有些窗口包含“a'用户''passw'”)