TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: laidbacklarry on September 19, 2012, 11:08:11 AM

Title: Need a CrashACAD program/technique
Post 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?
Title: Re: Need a CrashACAD program/technique
Post by: MP on September 19, 2012, 11:14:49 AM
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.
Title: Re: Need a CrashACAD program/technique
Post by: Drafter X on September 19, 2012, 11:19:32 AM
well... yank the plug out of the wall with no UPS, should simulate it pretty well I would think.  :lol:
Title: Re: Need a CrashACAD program/technique
Post by: Lee Mac on September 19, 2012, 11:25:58 AM
Terminate the acad process in the task manager?
Title: Re: Need a CrashACAD program/technique
Post by: Drafter X on September 19, 2012, 11:45:23 AM
Terminate the acad process in the task manager?

And yeah, then there is the boring way.
Title: Re: Need a CrashACAD program/technique
Post by: Lee Mac on September 19, 2012, 11:45:53 AM
Terminate the acad process in the task manager?

And yeah, then there is the boring way.

 :lol:
Title: Re: Need a CrashACAD program/technique
Post by: Chris on September 19, 2012, 01:11:33 PM
Personally, I prefer MP's method
Title: Re: Need a CrashACAD program/technique
Post by: Drafter X on September 19, 2012, 01:20:33 PM
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
Title: Re: Need a CrashACAD program/technique
Post by: MP on September 19, 2012, 01:33:26 PM
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.
Title: Re: Need a CrashACAD program/technique
Post by: MP on September 19, 2012, 03:52:46 PM
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.

Code: [Select]
(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.
Title: Re: Need a CrashACAD program/technique
Post by: ronjonp on September 19, 2012, 04:28:34 PM
Quote
;;  UNTESTED: USE AT YOUR OWN FCKUING RISK
  :lmao:
Title: Re: Need a CrashACAD program/technique
Post by: MP on September 20, 2012, 11:23:39 AM
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.
Title: Re: Need a CrashACAD program/technique
Post by: laidbacklarry on September 20, 2012, 12:37:56 PM
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...
Title: Re: Need a CrashACAD program/technique
Post by: MP on September 20, 2012, 01:00:33 PM
Your welcome, thanks, and have fun. :)
Title: Re: Need a CrashACAD program/technique
Post by: dgorsman on September 20, 2012, 01:28:37 PM
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.
Title: Re: Need a CrashACAD program/technique
Post by: Drafter X on September 21, 2012, 08:16:01 AM
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:
Title: Re: Need a CrashACAD program/technique
Post by: MP on November 28, 2014, 03:43:33 PM
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:

Code: [Select]
(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.