Solved

Batch File to run all vbscripts in a folder

Posted on 2014-03-04
12
534 Views
Last Modified: 2014-03-05
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
Comment
Question by:kingbc
  • 4
  • 4
  • 3
  • +1
12 Comments
 
LVL 69

Assisted Solution

by:Qlemo
Qlemo earned 333 total points
ID: 39905005
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
 
LVL 13

Expert Comment

by:Santosh Gupta
ID: 39905015
forfiles /p D:\scripts\ /m *.vbs /c "cmd /c wscript @file"
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 167 total points
ID: 39905025
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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 69

Expert Comment

by:Qlemo
ID: 39905064
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
 

Author Comment

by:kingbc
ID: 39905506
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
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39905551
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
 

Author Comment

by:kingbc
ID: 39906997
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
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39907071
on mobile at mo, but try syntax suggested in my last post using di and "" around filename.

Steve
0
 
LVL 69

Assisted Solution

by:Qlemo
Qlemo earned 333 total points
ID: 39907090
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
 

Author Comment

by:kingbc
ID: 39907160
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
 

Author Closing Comment

by:kingbc
ID: 39907169
Thanks to Steve (dragon-it) for the fast response times on my questions!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39907244
No problem, glad it helped.

Steve
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question