Log in

View Full Version : VBA Process ID of object i open



ry94080
07-29-2016, 02:10 PM
Hi all,

I use the following code to open up an object and run some scripts.

Function MisysLogonScript(sDept As String)
Dim sSettings As String
sDir = "C:\Users\" & UserNameWindows & "\AppData\Roaming\PendingLog\"
sTextFileName = "PendingLog.txt"
sSettings = "C:\Users\" & UserNameWindows & "\AppData\Roaming\PendingLog\PendingLog.r4w"
Set oSession = New Reflection4.Session

With oSession
.Visible = True
.OpenSettings sSettings



How do I go about getting the Process ID of this session? The reason I ask is osession.quit and Set osession = nothing doesn't seem to be killing the process in the Task Manager. It leaves it hanging and I have to manually kill it.

I was hoping to get the process ID so I can kill it via VBA and not kill any other potential sessions running.

Any ideas?

jonh
07-29-2016, 02:39 PM
So, I have no idea what relection4 is. But I wonder why it's closure is a problem. This relevant?

http://stackoverflow.com/questions/23505272/how-do-i-reference-a-specific-external-app-window-object-in-vba

ry94080
07-29-2016, 03:15 PM
That post actually looks like the user is trying to control different open sessions.

I have a session that I open and run a pretty big script, the .close doesn't work. I believe it's a memory thing, because I've used .close before on short scripts and it works. The only thing that will work is killing the process in Task Manager. But if I kill it via VBA and use kill r4win.exe, it kills all open sessions. I was hoping to somehow identify the PID of the session I open through VBA, then kill it when the scripts are done running.

jonh
07-29-2016, 04:12 PM
Well as I said I don't know anything about r4.
Sounds like you need to look for documentation on how to check the status of running sessions or try to insert some sort of delay or maybe use doevents.