[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 552
  • Last Modified:

Batch File to run all vbscripts in a folder

I have an ever growing number of vbscripts that I set up scheduled tasks to run every 15 minutes and there's got to be a better way.  Is there a way to put together a batch file that will run every script in a particular folder?  That way I could just have one scheduled task to rule them all!  

Thanks in advance.
0
kingbc
Asked:
kingbc
  • 4
  • 4
  • 3
  • +1
3 Solutions
 
QlemoC++ DeveloperCommented:
Of course. e.g. with a cmd batch file:
@echo off
for %%F in (C:\Scripts\*.vbs) do cscript //nologo %%F

Open in new window

0
 
Santosh GuptaCommented:
forfiles /p D:\scripts\ /m *.vbs /c "cmd /c wscript @file"
0
 
Steve KnightIT ConsultancyCommented:
And if they can run at the same time you can do something like:

@echo off
for %%F in (C:\Scripts\*.vbs) do START ""  "cscript //nologo %%F"

And to make sure they run in a particular order use a dir command, e.g.

@echo off
cd /d c:\scripts
for /f "tokens=*" %%F in ('dir /b /a-d /o-d *.vbs') do cscript //nologo "%%~F"

That would do the newest first (/o-d), oldest first is /od
/on is alphanumeric filename order etc. i.e. name then 01-script.vbs, 02-something.vbs etc. or A_script.vbs, B_Script.vbs

etc.

Steve
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
QlemoC++ DeveloperCommented:
In regard of "in a particular order", usually you ascertain that by prefixing each file name with e.g. a two-digit number, ascending, and then use the DIR as shown above.
0
 
kingbcAuthor Commented:
Sounds like this should be straight forward yet I'm getting an error.  

"windows cannot find "cscript //nologo d:\scripts\file1.vbs......."
even though this file and others are in that location.

What am I missing?
0
 
Steve KnightIT ConsultancyCommented:
Please post your code.  are there spaces in the path or filenames?  Have you tried with suitable " " around the paths like in my last example?

Steve
0
 
kingbcAuthor Commented:
Thanks Steve
Below is the code.  The contents of the folder get interated as expected as the error messages shows as much;

---------------------------------------
The system cannot find the file cscript //nologo C:\Users\bking\Documents\Scripts\EnvMon\Tasks\file1.vbs.
The system cannot find the file cscript //nologo C:\Users\bking\Documents\Scripts\EnvMon\Tasks\file2.vbs.
The system cannot find the file cscript //nologo C:\Users\bking\Documents\Scripts\EnvMon\Tasks\file3.vbs.

----------------------------------------
Exit code: 1 , 0001h

@echo off
for %%F in (C:\Users\bking\Documents\Scripts\EnvMon\Tasks\*.vbs) do START "" "cscript //nologo %%F"

Open in new window

0
 
Steve KnightIT ConsultancyCommented:
on mobile at mo, but try syntax suggested in my last post using di and "" around filename.

Steve
0
 
QlemoC++ DeveloperCommented:
If using Steve's suggestion, we have to modify that a bit:
@echo off
for %%F in (C:\Users\bking\Documents\Scripts\EnvMon\Tasks\*.vbs) do START "" cscript //nologo "%%~F"

Open in new window

0
 
kingbcAuthor Commented:
Deleting the quotes around the cscript //nologo %%F section did the trick.  Problem solved, points to be shared since both dragon-it and qlemo provided essentially the same solution.  Thanks to all!
0
 
kingbcAuthor Commented:
Thanks to Steve (dragon-it) for the fast response times on my questions!
0
 
Steve KnightIT ConsultancyCommented:
No problem, glad it helped.

Steve
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 4
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now