TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: laidbacklarry on September 19, 2012, 11:08:11 AM
-
Well, I guess I could just unplug the system, but that would lead to lengthy restarts. I'd like to be able to crash ACAD to explore the various files left after a crash. Need to write a tech bulletin on recovering from a combined power outage and bad UPS battery. Any ideas?
-
Use it in a production environment on a high priority project with immediate delivery deadline -- the "mission critical detector" should cause it to crash promptly.
-
well... yank the plug out of the wall with no UPS, should simulate it pretty well I would think. :lol:
-
Terminate the acad process in the task manager?
-
Terminate the acad process in the task manager?
And yeah, then there is the boring way.
-
Terminate the acad process in the task manager?
And yeah, then there is the boring way.
:lol:
-
Personally, I prefer MP's method
-
I cant tell you how many times I have been tempted to combine MP's method and my own, its that little evil thing in my head that says
'you could just reach out and yank that power cord'
So far I have resisted..
... so far
-
Lulz aside you can use the Process.Kill function available in the .NET runtime (TerminateProcess in Win32 if memory serves) or if you don't want to roll yer own I think there's a KillProcess type function in DOSLIB.
-
VBScript to kill a process (http://msdn.microsoft.com/en-us/library/windows/desktop/aa393907%28v=vs.85%29.aspx).
Why vbscript? Because it's dead simple to convert vbscript code to lisp. Look around the swamp (search the swamp for "WbemScripting.SWbemLocator") and you should find lots of examples. Here's a quick, read UNTESTED, attempt to translate to lisp.
(defun _KillProcess ( name / wmiLocater wmiService queryResult result )
;;================================================================
;;
;; 2012/09/19 | Quick & Dirty | Michael Puckett
;;
;; UNTESTED: USE AT YOUR OWN FCKUING RISK
;;
;; e.g. (_KillProcess "notepad.exe")
;;----------------------------------------------------------------
(vl-load-com)
(vl-catch-all-apply
'(lambda ( )
(vlax-for item
(setq queryResult
(vlax-invoke
(setq
wmiLocater (vlax-create-object "WbemScripting.SWbemLocator")
wmiService (vlax-invoke wmiLocater 'ConnectServer "." "root\\cimv2")
)
'ExecQuery
(strcat
"SELECT * FROM Win32_Process WHERE Name = '"
name
"'"
)
)
)
(vlax-invoke item 'Terminate)
(setq result T)
)
)
)
(if queryResult (vlax-release-object queryResult))
(if wmiService (vlax-release-object wmiService))
(if wmiLocater (vlax-release-object wmiLocater))
result
)
e.g. (KillProcess "notepad.exe")
Cheers.
Edit: Fixed a couple trivial typos.
-
;; UNTESTED: USE AT YOUR OWN FCKUING RISK
:lmao:
-
Keep in mind the simplistic function I posted is indiscriminant -- it will attempt to kill all instances matching the argument name.
In the case of a desired suicide, i.e. (_KillProcess "acad.exe"), it would be better to dermine the ProcessID (PID) of the current instance (probably via the HWND), and then kill the process by said PID, i.e. ... (strcat "SELECT * FROM Win32_Process WHERE ProcessID = " process_id) ... etc.
As penned, (_KillProcess "acad.exe") would merely try to kill all instances of "acad.exe", and if there is more than one running instance there's high probability an "innocent" instance would be terminated before the current desired instance. While a fun challenge I've other fish to fry at present; enjoy.
-
MP - Thanks, I'll test it on an old, really old, laptop later. Will let you know results... hey, I knew this would provide a little fun, but it really may be useful...
-
Your welcome, thanks, and have fun. :)
-
If you want a proper crash, rather than just terminating the program, how about an exponential copy routine? Draw a circle (or create a complex 3D solid); copy it, for two; copy those two, for four; copy those four, for eight; repeat until AutoCAD screams for mercy.
-
make a series of offset ellipses cut by straight lines, hatch it associatively and then stretch the ellipses?
I always do that with beta versions of autocad and seems to give me a decent idea of how stable that iteration is. :evil:
-
I had need to use this tool today and found to my dismay it wouldn't run under 64 bit Windows (7 Pro), so I quickly bashed out an alternate:
(defun _KillProcess ( process_name / @try shell filename handle )
;; Written by Michael Puckett, 2014
(defun @try ( try_statement ) ;; dumbed down version of mp.lsp: _Try
(vl-catch-all-apply
(function
(lambda ( )
(eval try_statement)
)
)
)
)
(vl-load-com)
(setq
shell (vlax-create-object "Shell.Application")
filename (vl-filename-mktemp "kill.vbs")
handle (open filename "w")
)
(foreach x
(list
(strcat
"Set wmiService = GetObject(\"winmgmts:"
"{impersonationLevel=impersonate}!\\\\"
".\\root\\cimv2\")"
)
(strcat
"Set processList = wmiService.ExecQuery"
"(\"Select * from Win32_Process Where Name = '"
process_name
"'\")"
)
"For Each process in processList"
" process.Terminate()"
"Next"
"Set processList = Nothing"
"Set wmiService = Nothing"
)
(princ (strcat x "\n") handle)
)
(close handle)
(@try '(vlax-invoke shell 'ShellExecute "cscript.exe" filename "" "runas" 0))
(@try '(vlax-release-object shell))
;; It's tempting to delete the temp vbs file we created above
;; but due to asynchronous execution of the shell execution
;; relative to the execution of this lisp function it tends to
;; terminate the shell execution prematurely (subtitle: we finish
;; before it does), so we'll just have to live with the litter
;; we've generated.
(princ)
)
Example:
(_KillProcess "notepad.exe")
FWIW ... Cheers.