Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making the sheel function run synchronously?

Status
Not open for further replies.

thomasmcgeown

Technical User
Feb 6, 2002
27
GB
By default, the Shell function runs other programs asynchronously, this causes me a problem in that a file hasnt been completly finished being written before vb tries to read it, casuing a list to not fully populate.
The time taken to write the file can vary immensly depending on the conditions, so a simple pause for xx seconds wont work...

any suggestions?

Kind Regards

Tom
 
you have to wait until the application has finished its task...


try with:

Dim id As String
Declare Function API_OpenProcess Lib "kernel32" Alias "OpenProcess" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

id = Shell("C:\EXE\cmd.EXE")

Do While (API_OpenProcess(PROCESS_ALL_ACCESS, False, id))

DoEvents
Loop

hope this could help you.

bye
D.
 
You could try searching the forum for "Shell", there are many solutiions to this situation listed.

Among these is Thread222-656566


Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Thanks for your suggestions.

In the end i made the batch add a particular string to the end of the text file it was creating, then stuck a loop so that the code would not continue unless this string was present...

======================================
Do Until intEndTest = 1
Do Until txtFile.AtEndOfStream
strLine2 = txtFile.ReadLine
If strLine2 = "My test string." Then_ intEndTest = 1
Loop
Loop
=======================================

Thanks again for your help.

Regards
Tom
 
If you include a reference to the Windows Host Scripting
Code:
Object, you can use the following code:

   Dim RetVal As Long
   Dim WSH As IWshShell
   Dim WaitForTermination as Boolean
   Dim CommandLine as String

   Set WSH = New IWshShell_Class
   CommandLine = "notepad.exe"
   WaitForTermination = True
   RetVal = WSH.Run(CommandLine, vbNormalFocus, WaitForTermination)
   MsgBox "Process returned: " & RetVal
   Set WSH = Nothing

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top