2014-10-01 79 views
2

我想讓這個批處理文件運行很多事情,它只輸入最後一個vbs行到實際的vbs文件。如何使用批處理創建一個vbs文件

:run 
cls 
color 0a 
cd "%userprofile% \desk" 
if exist run1.vbs del run1.vbs 
copy Nul "run1.vbs" 

echo set b=createobject("wscript.shell") >> "run1.vbs" 
echo x=inputbox ("type:") > "run1.vbs" 
echo strtext = (x) > "run1.vbs" 

echo if x=("exe") then > "run1.vbs" 
echo y=inputbox("run:") > "run1.vbs" 

echo b.run (y) > "run1.vbs" 
echo end if > "run1.vbs" 
echo if x=("spam") then > "run1.vbs" 
echo z=inputbox ("spam:") > "run1.vbs" 
echo wscript.sleep 2000 > "run1.vbs" 
echo for var = 1 to 50 > "run1.vbs" 
echo b.sendkeys z > "run1.vbs" 
echo b.sendkeys "{ENTER}" > "run1.vbs" 
echo next > "run1.vbs" 
echo end if > "run1.vbs" 

cd "%userprofile% \desk" 
start run1.vbs 
ping -n 3 127.0.0.1>nul 

exit 
+2

從UNIX shell的體驗:'>'截斷該文件,然後寫進去。嘗試'>>'或Windows批處理用於追加運算符的任何內容。 – 2014-10-01 04:24:42

+1

靠近尾部的cd命令看起來不正確 - 刪除\之前的空格,並在cd後添加a/d,以防萬一您從另一個驅動器運行。 – cup 2014-10-01 04:51:25

+0

更好地檢查此:http://stackoverflow.com/questions/9074476/is-it-possible-to-embed-and-execute-vbscript-within-a-batch-file-without-using-a – npocmaka 2014-10-01 08:13:14

回答

0

最好嘗試創建一個hybrid file

<!-- : Begin batch script 
@echo off 

:run 
cls 
color 0a 
cd "%userprofile%\desk" 

cscript //nologo "%~f0?.wsf" 

ping -n 3 127.0.0.1>nul 
exit /b 

----- Begin wsf script ---> 
<job><script language="VBScript"> 

    set b=createobject("wscript.shell") 
    x=inputbox ("type:") 
    strtext = (x) 

    if x=("exe") then 
    y=inputbox("run:") 

    b.run (y) 
    end if 
    if x=("spam") then 
    z=inputbox ("spam:") 
    wscript.sleep 2000 
    for var = 1 to 50 
    b.sendkeys z 
    b.sendkeys "{ENTER}" 
    next 
    end if 
</script></job> 
相關問題