2

I'm trying to make this batch file that runs a lot of things and it only inputs the last vbs line in to the actual vbs file.

: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
benomatis
  • 5,035
  • 7
  • 30
  • 51
  • 2
    From Unix shell experience: `>` truncates the file, then writes into it. Try `>>` or whatever Windows batch uses for the append operator. – Jeffrey Bosboom Oct 01 '14 at 04:24
  • 1
    The cd command near the end doesn't look right - remove the space before the \ and add a /d after the cd, just in case you are running from a different drive. – cup Oct 01 '14 at 04:51
  • better check this: http://stackoverflow.com/questions/9074476/is-it-possible-to-embed-and-execute-vbscript-within-a-batch-file-without-using-a – npocmaka Oct 01 '14 at 08:13

1 Answers1

0

Better try to create a 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>
Community
  • 1
  • 1
npocmaka
  • 51,748
  • 17
  • 123
  • 166