Wait until certain external process has stopped

eatraas

Registered User.
Local time
Today, 01:24
Joined
Jan 23, 2009
Messages
96
Hi,

I'm running an external program from access and I want to wait until this is done to go further with the next code line.

I've tried a number of this like
Dim wsh As Object Set wsh = VBA.CreateObject("WScript.Shell") Dim waitOnReturn As Boolean: waitOnReturn = True Dim windowStyle As Integer: windowStyle = 1 wsh.Run "C:\folder\mf.exe", windowStyle, waitOnReturn

This is rather old and does not work, perhaps a reference problem.

Does anyone have an idea?

Thanks in advance

Erwin
 
Hi Erwin. Have you tried ShellWait?

 
Yes i did, native access does not support this, which reference is needed for this? Sorry this was another one.
I see the code is using some 32 bits references, i need it to work on both 32 and 64 bits office installations.
 
Last edited:
What does mf.exe do?
Could you check to see it is running?
 
MF is an own utility which combines a number of files into one pdf, yes at that moment it is running.
Could be anything of course, like notepad.exe.
 
No, I meant check to see if it running in system processes, with code?
 
I see the code is using some 32 bits references, i need it to work on both 32 and 64 bits office installations.
Try this one.

 
Erwin
We just migrated to 64-bit 2019 and replaced our API calls with wscript.shell and it works great.

Much better.
What does not work mean?

Wayne
 
No, I meant check to see if it running in system processes, with code?
this :

Code:
Function IsProcessRunning(process As String)
Dim objList As Object

Set objList = GetObject("winmgmts:") _
    .ExecQuery("select * from win32_process where name='" & process & "'")

If objList.Count > 0 Then
    IsProcessRunning = True
Else
    IsProcessRunning = False
End If

End Function
 
but that code does not wait until the process is done, just kills an existing process. I want to wait.
Just curious... Did you see my last post? Have you tried it?
 
I do not see that killing any process? :unsure:
I was thinking along the lines of pausing any way you like until that function is false?, then you can continue with the rest of your code?
 
Erwin
Stay with wscript.shell.
Fix your reference... or whatever.
Its the least complex solution.

Wayne (can't type on iphone)
 
Erwin
Stay with wscript.shell.
Fix your reference... or whatever.
Its the least complex solution.

Wayne (can't type on iphone)
Yes, i tried it but is not working, if you read the article it is also not working for this person, i'm geeting the same error
 
Yes, i tried it but is not working, if you read the article it is also not working for this person, i'm geeting the same error
Sorry, but I feel like you're ignoring me. If you don't want my help, I'm okay with that. Good luck!
 
is solved in an other way, the sheel program was making a new files and this was taking some time:
I solved it by creating a loop which checks if the file is existing, and exits the loop when the file exists , like

Code:
draait = False
Dim FilePath As String
FilePath = "c:\tmp\somefile.pdf"
Set FSO = CreateObject("scripting.filesystemobject")

Do Until draait = True
 If FSO.FileExists(FilePath) = True Then
   draait = True
 End If
 
Loop
 
is solved in an other way, the sheel program was making a new files and this was taking some time:
I solved it by creating a loop which checks if the file is existing, and exits the loop when the file exists , like

Code:
draait = False
Dim FilePath As String
FilePath = "c:\tmp\somefile.pdf"
Set FSO = CreateObject("scripting.filesystemobject")

Do Until draait = True
If FSO.FileExists(FilePath) = True Then
   draait = True
End If

Loop
Hi. Glad to hear you got it sorted out. Good luck with your project.
 
Erwin,
I still don't know why your original wasn't working.
Thats the best method.

Your current workaround is based on --> if the file exists; its done.

That isn't always the case.

At least have the shelled process make a new file AFTER the real file completes.en

You can --> echo >> im_done.txt

Then you know the original is really do e.

Either way it'd be better to get the wait working.

Wayne
 

Users who are viewing this thread

Back
Top Bottom