Wait until certain external process has stopped (1 Viewer)

eatraas

Registered User.
Local time
Yesterday, 19: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
 

eatraas

Registered User.
Local time
Yesterday, 19:24
Joined
Jan 23, 2009
Messages
96
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:

Gasman

Enthusiastic Amateur
Local time
Today, 03:24
Joined
Sep 21, 2011
Messages
14,287
What does mf.exe do?
Could you check to see it is running?
 

eatraas

Registered User.
Local time
Yesterday, 19:24
Joined
Jan 23, 2009
Messages
96
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.
 

Gasman

Enthusiastic Amateur
Local time
Today, 03:24
Joined
Sep 21, 2011
Messages
14,287
No, I meant check to see if it running in system processes, with code?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:24
Joined
Oct 29, 2018
Messages
21,471
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.

 

WayneRyan

AWF VIP
Local time
Today, 03:24
Joined
Nov 19, 2002
Messages
7,122
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
 

eatraas

Registered User.
Local time
Yesterday, 19:24
Joined
Jan 23, 2009
Messages
96
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
 

Gasman

Enthusiastic Amateur
Local time
Today, 03:24
Joined
Sep 21, 2011
Messages
14,287
Yes, something like that.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:24
Joined
Oct 29, 2018
Messages
21,471
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?
 

Gasman

Enthusiastic Amateur
Local time
Today, 03:24
Joined
Sep 21, 2011
Messages
14,287
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?
 

WayneRyan

AWF VIP
Local time
Today, 03:24
Joined
Nov 19, 2002
Messages
7,122
Erwin
Stay with wscript.shell.
Fix your reference... or whatever.
Its the least complex solution.

Wayne (can't type on iphone)
 

eatraas

Registered User.
Local time
Yesterday, 19:24
Joined
Jan 23, 2009
Messages
96
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
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:24
Joined
Oct 29, 2018
Messages
21,471
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!
 

eatraas

Registered User.
Local time
Yesterday, 19:24
Joined
Jan 23, 2009
Messages
96
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
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:24
Joined
Oct 29, 2018
Messages
21,471
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.
 

WayneRyan

AWF VIP
Local time
Today, 03:24
Joined
Nov 19, 2002
Messages
7,122
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

Top Bottom