rilliam
asked on
VBS to run all exe in specified directory
I am trying to make a script that will run all the exe files in a specified directory. The script I have so far seems to run the bat files randomly. For testing I set up a folder with a.bat, b.bat and c.bat where a.bat runs notepad, b.bat runs calc, and c.bat runs appwiz.cpl. What happens seems totally randomly to me, sometimes calc runs, sometimes appwiz, sometimes notepad. I don't think I have seen all of them start like they are supposed to. What am I doing wrong? Here is my script:
Dim fso, startFolder
Dim WshShell, oExec
Dim folder, file, fileCollection
Set WshShell = CreateObject("WScript.Shel l")
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
startFolder = "C:\test"
Set folder = fso.GetFolder(startFolder)
Set fileCollection = folder.Files
For Each file In fileCollection
If UCase(Right(file.Name, 4)) = ".BAT" Then
Set oExec = WshShell.Exec(file.name)
End If
Next
I will probably make this into an exe in vb6, so if anybody already knows how to do this in vb6 it would save me time.
Dim fso, startFolder
Dim WshShell, oExec
Dim folder, file, fileCollection
Set WshShell = CreateObject("WScript.Shel
Set fso = CreateObject("Scripting.Fi
startFolder = "C:\test"
Set folder = fso.GetFolder(startFolder)
Set fileCollection = folder.Files
For Each file In fileCollection
If UCase(Right(file.Name, 4)) = ".BAT" Then
Set oExec = WshShell.Exec(file.name)
End If
Next
I will probably make this into an exe in vb6, so if anybody already knows how to do this in vb6 it would save me time.
your code should work in VB6
>What happens seems totally randomly to me,
What order do you want to run them in?
Leon
What order do you want to run them in?
Leon
ASKER
doesn't matter to me, alphabetical I guess. Whatever is easiest.
Yes, it does kind of work in vb6...usually it just runs and does nothing.
Yes, it does kind of work in vb6...usually it just runs and does nothing.
>doesn't matter to me, alphabetical I guess. Whatever is easiest.
Easiest would be to let it run as it does now, letting it choose the order. To sort them you would have to read the names into an array, sort them and then pass in each one at a time to run.
Easiest would be to let it run as it does now, letting it choose the order. To sort them you would have to read the names into an array, sort them and then pass in each one at a time to run.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.