Jump to content

Recommended Posts

Posted

Hello CADTutor members,

I found a code by Lee Mac to open a folder by AutoLISP here.

The code follows:

(defun MT-Explore (Directory / Shell result)
   (setq Shell (vla-getInterfaceObject (vlax-get-acad-object)
                                       "Shell.Application"
               )
   )
   (setq result
            (vl-catch-all-apply 'vlax-invoke (list Shell 'Explore Directory))
   )
   (vlax-release-object Shell)
   (not (vl-catch-all-error-p result))
)

Should anyone know how to close the opened folder?

Posted

The only thing that comes to mind is a Termination script, but such methods are dangerous if you terminate the wrong process - so be careful.

 

(defun LM:Terminate ( process / wmi server query name )
 (vl-catch-all-apply
   (function
     (lambda ( / name )
       (setq process (strcase process)
             wmi     (vlax-create-object "WbemScripting.SWbemLocator")
             server  (vlax-invoke wmi 'connectserver nil nil nil nil nil nil nil nil)
             query   (vlax-invoke server 'execquery "Select * from Win32_Process")
       )
       (vlax-for item query
         (if
           (and
             (setq name (vlax-get item 'commandline))
             (vl-string-search process (strcase name))
           )
           (vlax-invoke item 'terminate)
         )
       )
     )
   )
 )
 (foreach object (list wmi server query)
   (if (and object (not (vlax-object-released-p object)))
     (vlax-release-object object)
   )
 )
)

 

Call with name of process to terminate, e.g.:

 

(LM:Terminate "Excel.exe")

Posted

How would that work though, i.e. a folder does not have its own process as far as I am aware and comes under the explorer.exe process. Terminating that will shutdown the taskbar and all other folder functionality, not just one folder.

Posted

How hard is it to click on the little "X" at the top right of the window or type ALT+F4 or CTRL+W?

Posted
How hard is it to click on the little "X" at the top right of the window or type ALT+F4 or CTRL+W?

 

True, but I'm positive that same argument could be applied to many of the tasks for which we write code - I'm sure you'll agree that it is often interesting to see if something can be achieved programmatically.

 

In this case however, I doubt a programmatic method will be found.

 

Lee

Posted
True, but I'm positive that same argument could be applied to many of the tasks for which we write code - I'm sure you'll agree that it is often interesting to see if something can be achieved programmatically.

 

In this case however, I doubt a programmatic method will be found.

 

Lee

Sort-of agree.

 

In this situation, I don't see how it's possible. Even if you could isolate active windows explorer windows, how would you isolate the specific one, if more than one is open.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...