I have a folder filled with few vbscripts (say 10) which has to be run sequentially, Instead of running each by clicking on them i want to automate this process. Below is my master.vbs script which runs each vbscript in that folder one by one.
strComputer = "."
Set objFSO = CreateObject("Scripting.FileSystemObject")
currentdirectory = objFSO.GetAbsolutePathName(".")
filedirectory = currentdirectory
Set objFolder = objFSO.GetFolder(filedirectory)
Dim filestring
Set colFiles = objFolder.Files
For Each objFile in colFiles
'Wscript.Echo objFile.Name
filestring = filestring & objFile.Name & ","
Next
'filestring = filestring.Trim().Substring(0, filestring.Length - 1)
filestring = Left(filestring,Len(filestring)-1)
Dim files
files = Split(filestring,",")
For Each f In files
'WScript.Echo f
chk = Split(f,".")
If chk(UBound(chk)) = "vbs" then
pat = filedirectory & "\" & f
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
proc = "cmd.exe /c"& Chr(32) &"cscript.exe " & Chr(32) & chr(34) & pat & Chr(34)
objWMIService.Create proc , null, null, intProcessID
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colMonitoredProcesses = objWMIService.ExecNotificationQuery _
("Select * From __InstanceDeletionEvent Within 1 Where TargetInstance ISA 'Win32_Process'")
Do Until i = 1
Set objLatestProcess = colMonitoredProcesses.NextEvent
If objLatestProcess.TargetInstance.ProcessID = intProcessID Then
i = 1
End If
Loop
'Wscript.Echo "Process has been terminated."
End If
Next
The issue i have here is that the scripts are running perfectly by since the process name is going to be the same for all the scripts (cscript) It doesnt wait for a process to terminate before starting another .
I understand there is just minute tweaking required in my code but im not sure how to go about it. Can some one point out what im doing wrong here ?..