hexagon logo

VB code/ If a program is running

Does anyone know what code would be used to find out if a program is currently running in PC-Dmis? I wrote some code to automate the execution process and if I use it while a program is running, it closes the program and opens the new program while the original program continues to run. (Not sure for how long though. I stopped it after I tested it.)
Parents
  • It looks like operator but you can still access the edit window if you go through the menu View-Edit Window. IF PC-Dmis is already open, this doesn't happen.


    I have a general warning for folks starting a pc-dmis on-line session using CreateObject (or any method I tried). Things DO NOT work right. I believe it's because our code is getting ahead of the pcd initialization process. What I observed is that very important pc-dmis messages were being suppressed. None of these messages were displayed:

    - "Select Probe File" (when pcd is launched)
    -"Program is using a probe that is not defined" (when program is opened)
    -" Program is using a tip that is not calibrated! (when program opened)

    You'll also find that when pc-dmis is exited, it will still be running in the task manager process list, and it won't respond to Application.Quit in your code. Kill it with task manager, and any settings changes made during the pcd session are lost. It's a mess.

    The key is to wait until pcd is ready. The question is, "when is that?"

    Application.WaitUntilReady() is a joke. Doesn't wait for anything far as I can tell. I beat my head against the wall trying to figure this out. Different machine interfaces and computers are ready at differing intervals. Finally decided to try waiting for a pc-dmis window to appear. Initially tried waiting for the "Select Probe File" window, which worked on all machines but two that use DME interface. Eventually settled on waiting for the pc-dmis Open window. Then I execute the CreateObject() command. We implement standard settings across all machines, one of which is to always show the pcd Open dialog at startup. We do this with batch files/registry import files.

    In our start pcd batch files, the event handler .exe is started before pc-dmis, and sits waiting for the pc-dmis Open dialog to appear.

    I use FindWindowEx from the Windows API (user32.dll) in a loop with Thread.Sleep() to wait for the window to appear.

    I use a Timer where the Timer.Elapsed event handler looks for pcd to become invisible(every 10 seconds), which is my cue that the user is trying to close pcd, and I need to close the event handler. I've found that the vb "End" command closes pcd gracefully, solving the problem above.

    Wish I could post my code...


  • You had your chance dude. Lol.

    I don't like complicating things like this. Is indeed fun.i enjoy like making it work. Been doing this a long time and have come to realize that simple is better. Force into it though. Only responding to the onopen event. To make a little edit to the programs before they run. Ill be adding cmm error logs when I have time, and that'll be it. Maybe. Wink
Reply
  • You had your chance dude. Lol.

    I don't like complicating things like this. Is indeed fun.i enjoy like making it work. Been doing this a long time and have come to realize that simple is better. Force into it though. Only responding to the onopen event. To make a little edit to the programs before they run. Ill be adding cmm error logs when I have time, and that'll be it. Maybe. Wink
Children
No Data