Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Windows task manager, kill process via lisp

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
bhull1985
1296 Views, 4 Replies

Windows task manager, kill process via lisp

Besides the vlax-release-object method is there a way that I can ENSURE that the background process (specifically, EXCEL.EXE) is closed in my routine?

The need is because if I open excel, make some changes or even not make any changes.....close excel....the background process for EXCEL.EXE is still running. This is via double-clicking method of opening excel....I would handle it via the vlax commands in my routine but I want to have a line that will pre-emptively close the background process so that i can start it right back up again.

Closest i've found is lee mac's running processes function....combined with a call to (member), but perhaps there is a better way?

For reference, credits to LeeMac

;(defun runningprocesses ( / qry rtn srv wmi )
;    (if (setq wmi (vlax-create-object "wbemscripting.swbemlocator"))
;        (progn
;            (setq rtn
;                (vl-catch-all-apply
;                   '(lambda ( / lst )
;                        (setq srv (vlax-invoke wmi 'connectserver)
;                              qry (vlax-invoke srv 'execquery "Select * from Win32_Process")
;                        )
;                        (vlax-for itm qry
;                            (vlax-for prp (vlax-get itm 'properties_)
;                                (if (= "name" (strcase (vlax-get prp 'name) t))
;                                    (setq lst (cons (vlax-get prp 'value) lst))
;                                )
;                            )
;                        )
;                        lst
;                    )
;                )
;            )
;            (foreach obj (list qry srv wmi)
;                (if (= 'vla-object (type obj))
;                    (vlax-release-object obj)
;                )
;            )
;            (if (vl-catch-all-error-p rtn)
;                (prompt (vl-catch-all-error-message rtn))
;                rtn
;            )
;        )
;    )
;)

 Thanks in advance!

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
4 REPLIES 4
Message 2 of 5
dbroad
in reply to: bhull1985

It sounds like a bad idea to try to kill a running application, assuming that it might only be a background process.

 

In general, when using lisp, if you don't want to duplicate running apps, try using vlax-get-or-create-object rather than vlax-create-object.  This keeps you from spawning more instances of Excel.

 

If you create a new excel.application object, then you need to keep up with all the references to the object or localize them.  When they go out of scope, you should be able to run the garbage collector to close the external application.  (gc)

 

I try to release objects in the reverse order in which they were create AND localize them.  Checking the return value of the vlax-release-object can help give you clues about whether there are still references to the object.  

 

HTH

 

One more item:  The help files for vlax-release-object state: "If an object-associated application does not close after calling the (gc) function, the (vlax-release-object) function was not called for all objects outside AutoCAD"

Architect, Registered NC, VA, SC, & GA.
Message 3 of 5
Lee_Mac
in reply to: bhull1985

Are you calling the quit method of the Excel Application object before releasing the various vla-objects?

Message 4 of 5
bhull1985
in reply to: Lee_Mac

Lee- I have not tried that, whoops, should have looked into that before posting here.

Should take care of it.

There is quite a bit to keep up with in manipulating external programs via lisp I must say!

One would think there could be easier ways, but I imagine there are reasons it's as complicated as is it.

(vlax-get-or-create-object)

 

and then maybe (vlax-close-object) that'd close the instance, background process, and all pointers but meh, I just need to do more studying and use what's available!

 

Thanks

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 5 of 5
Shneuph
in reply to: bhull1985

If I didn't appreciate the knowledge, talent, and support of every user in this thread so much I would ask, "WHY are we still using AutoLISP/VisualLISP and not VB.NET!?" Smiley Surprised

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

”Boost