How to execute/hold execution of a vbscript program until the same vbscript program ends its previous execution?

Hi,
   I am using vbscript to read a txt file and display it using MSComm. I need to hold the execution of vbscript until the previous execution of the same vbscript program ends. First time vbscript program will execute with a set of txt values, Mean while if the same vbscript program is executed with a second set of txt values, I want to hold/put the execution in a queue until the previous execution ends.
Please help me in this case how to proceed.

Thanks

Jerald Silvester
jeraldsilvester_laAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ExcelGuideConsultantCommented:
ok, but why dont you create a for loop for 2 executions?

So first he will execute the first one and then after the first one finishes it will start the second one.

If it is not the exact the same code, then you can refer to the second code in the first code...right?

I hope this will help you.

Good luck
0
RobSampsonCommented:
Hi, Psychotec's option is a good one, try to merge the two scripts together, however, if you don't want to do that, you have a couple of options....

1)  Don't run the second script "explicitly" on it's own.  Have the first script run the second script, at the completion of the first script, by using this:
   Set objShell = CreateObect("WScript.Shell")
   strSecondVBSPath = "C:\Temp\Script2.vbs"
   objShell.Run "wscript """ & strSecondVBSPath & """", 1, True

2)  Use a third script to call the two in sequence, using:
   Set objShell = CreateObect("WScript.Shell")
   strFirstVBSPath = "C:\Temp\Script1.vbs"
   strSecondVBSPath = "C:\Temp\Script2.vbs"
   objShell.Run "wscript """ & strFirstVBSPath & """", 1, True
   objShell.Run "wscript """ & strSecondVBSPath & """", 1, True

It is the True on the end of the Run statement that will make the script wait for that command to complete.

Regards,

Rob.
0
jeraldsilvester_laAuthor Commented:
Hi,
    No, I am using only one script(disp.vbs) which takes a text file(a1.txt). This displays the content in digital display board. Say this takes about 2 minutes. Meanwhile If user tries to execute the same script(disp.vbs) with the second set of values in another text file(a2.txt), I want to hold the second call of this script or put this in queue until the first gets executed. Currently I get PortOpen error (Err=8005).
Hope I've delivered my issue in a better way now.. :-)

Thanks & Regards,
Jerald
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

ExcelGuideConsultantCommented:
you should work with error handlers, something like

If Err.Number = 8005 then
Msgbox "Another script is working, waiting for 2 minutes..."
Application.Wait Now + TimeValue("00:02:00")
'Refer to your macro here, like
Run "YourMacro"
end if

Good luck
0
ExcelGuideConsultantCommented:
owww btw look which line give the error and put this code above:

On Error GoTo Err1:
...your code...

If Err.Number = 8005 then
Msgbox "Another script is working, waiting for 2 minutes..."
Application.Wait Now + TimeValue("00:02:00")
'Refer to your macro here, like
Run "YourMacro"
end if

Good luck
0
RobSampsonCommented:
Psychotec is right.  When you run the script a second time, you should get a line number where the error occurs.....
Let's say, for example, the error is on line 23, which might be
objPorts.Open 2254

So, you can put
On Error Resume Next
objPorts.Open 2254
If Err.Number <> 0 Then
   MsgBox "There was an error getting the port. Try the script again later."
   wscript.Quit
End If
On Error GoTo 0
' rest of your code goes here.


Regards,'

Rob.
0
jeraldsilvester_laAuthor Commented:
Yes Friends..You both gave the soln which I've arrived to.
But, In my case, I cannot show msg to the user and make them wait until the previous display ends.
I want the second execution to wait till the first gets executed and then start executing the second one by itself. Any thoughts?????

Thanks & Regards,
Jerald Silvester
0
RobSampsonCommented:
Hmmm, for this you'd need to find out if any wscript.exe processes are running, and wait for them to finish.  I will try to find out if we can see which file a process has open.

Regards,

Rob.
0
RobSampsonCommented:
Actually, thinking about it overnight (not losing sleep over it though), all you need to do is wait for there to only be one wscript.exe process running, because that will the current script, waiting for others to finish....this should do that....

'=================
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select Name from Win32_Process WHERE Name='wscript.exe'")

If colProcess.Count > 1 Then MsgBox "A script is already running. Waiting for it to finish..."

While colProcess.Count > 1
      WScript.Sleep 2000
      Set colProcess = objWMIService.ExecQuery ("Select Name from Win32_Process WHERE Name='wscript.exe'")
Wend

MsgBox "This script will now run."

' Other stuff

MsgBox "Finished."
'=================

Regards,

Rob.
0
jeraldsilvester_laAuthor Commented:
Hi friends,
 I've solved this by checking the file existancy. as i was reading from a file for the contents to be displayed. so, I check for file existancy and proceed with the next call.
Thank you all for your post/suggestion.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RobSampsonCommented:
Fair enough. Would you be able to post a request to have this question PAQed or deleted?

Thanks,

Rob.
0
jeraldsilvester_laAuthor Commented:
Yes I request you to do so.

Thanks,
Jerald
0
RobSampsonCommented:
Jerald, you should be able to accept your own comment as the answer.  Is there a button for you to accept your comment?

Rob.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.