2017-12-02 1 views
0

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 
+0

그래서, 그 코드의 문제 무엇입니까? – omegastripes

+0

내 코드가 배치 파일을 실행하지 않습니다. – spiky

답변

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 

(그리고 "는 '사용자'passw '"같은 것을 포함하는 일부 창)

관련 문제