Author Topic: create-object with windows explorer  (Read 373 times)

0 Members and 1 Guest are viewing this topic.

mkweaver

  • Bull Frog
  • Posts: 352
create-object with windows explorer
« on: February 13, 2024, 05:01:21 PM »
I can open an explorer window to a path with this:  (startapp "Explorer"(strcat "/N, " pathname))
But if there is a window already open to that path, then I just want to activate it, not open a duplicate window.

Suggestions appreciated.

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: create-object with windows explorer
« Reply #1 on: February 13, 2024, 08:56:25 PM »
I'm not sure it can be done, I just had a look and a play with powershell with no luck.
https://superuser.com/questions/1787789/command-line-to-have-windows-explorer-open-folder-in-existing-instance-of-explor

anyway, I'd look up the command flags for explorer and try to get it working in cmd or powershell then you're all but done (if it can be done...) :)

"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: create-object with windows explorer
« Reply #2 on: February 14, 2024, 04:32:41 AM »
You might try the AppActivate method of the WSH -
https://learn.microsoft.com/en-us/previous-versions//wzcddbek(v=vs.85)

mkweaver

  • Bull Frog
  • Posts: 352
Re: create-object with windows explorer
« Reply #3 on: February 14, 2024, 12:37:23 PM »
Lee Mac and MickD,
Thanks for the suggestions.  I found something that may help, though it is a bit dated (refers to IE): https://learn.microsoft.com/en-us/windows/win32/shell/developing-with-windows-explorer

Quote
Open explorer windows can be discovered and programmed by using IShellWindows (CLSID_ShellWindows)...

I think using WSH to access this I'll be able to do what I want.

I'll post back what I find.

PKENEWELL

  • Bull Frog
  • Posts: 319
Re: create-object with windows explorer
« Reply #4 on: February 14, 2024, 01:08:05 PM »
I've been using this for years:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:EXPLORE ()
  2.    (if (= (getvar "dwgtitled") 1)
  3.       (startapp (strcat "explorer.exe /e,/select,\"" (getvar "dwgprefix") (getvar "dwgname") "\""))
  4.       (startapp (strcat "explorer.exe /e,\"" (getvar "dwgprefix") "\""))
  5.    )
  6.    (princ)
  7. )
  8.  
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

ronjonp

  • Needs a day job
  • Posts: 7529
Re: create-object with windows explorer
« Reply #5 on: February 14, 2024, 03:48:23 PM »
Lee Mac and MickD,
Thanks for the suggestions.  I found something that may help, though it is a bit dated (refers to IE): https://learn.microsoft.com/en-us/windows/win32/shell/developing-with-windows-explorer

Quote
Open explorer windows can be discovered and programmed by using IShellWindows (CLSID_ShellWindows)...

I think using WSH to access this I'll be able to do what I want.

I'll post back what I find.
This has been bugging me for years as well! I may have found the solution today ( works on my computer Win 11, Version 10.0.22631 Build 22631) A simple mod from 'explore to 'open.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:cd (/ _opendirectory)
  2.   (defun _opendirectory (path / sa)
  3.     (cond ((and (eq 'str (type path))
  4.                 (findfile (vl-string-right-trim "\\" path))
  5.                 (setq sa (vlax-create-object "Shell.Application"))
  6.            )
  7.            ;; ;; RJP » 2024-02-14
  8.            ;; Using 'open vs 'explore will not open multiple windows with the same path
  9.            (vlax-invoke sa 'open path)
  10.            (vlax-release-object sa)
  11.           )
  12.     )
  13.     (princ)
  14.   )
  15.   (_opendirectory (getvar 'dwgprefix))
  16. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

mkweaver

  • Bull Frog
  • Posts: 352
Re: create-object with windows explorer
« Reply #6 on: February 14, 2024, 05:17:10 PM »
Quote
This has been bugging me for years as well! I may have found the solution today ( works on my computer Win 11, Version 10.0.22631 Build 22631) A simple mod from 'explore to 'open.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:cd (/ _opendirectory)
  2.   (defun _opendirectory (path / sa)
  3.     (cond ((and (eq 'str (type path))
  4.                 (findfile (vl-string-right-trim "\\" path))
  5.                 (setq sa (vlax-create-object "Shell.Application"))
  6.            )
  7.            ;; ;; RJP » 2024-02-14
  8.            ;; Using 'open vs 'explore will not open multiple windows with the same path
  9.            (vlax-invoke sa 'open path)
  10.            (vlax-release-object sa)
  11.           )
  12.     )
  13.     (princ)
  14.   )
  15.   (_opendirectory (getvar 'dwgprefix))
  16. )

That is exactly the behavior I wanted!  Thanks!  Now I need to dig through some of my older code and switch to this.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: create-object with windows explorer
« Reply #7 on: February 14, 2024, 05:20:02 PM »
Quote
This has been bugging me for years as well! I may have found the solution today ( works on my computer Win 11, Version 10.0.22631 Build 22631) A simple mod from 'explore to 'open.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:cd (/ _opendirectory)
  2.   (defun _opendirectory (path / sa)
  3.     (cond ((and (eq 'str (type path))
  4.                 (findfile (vl-string-right-trim "\\" path))
  5.                 (setq sa (vlax-create-object "Shell.Application"))
  6.            )
  7.            ;; ;; RJP » 2024-02-14
  8.            ;; Using 'open vs 'explore will not open multiple windows with the same path
  9.            (vlax-invoke sa 'open path)
  10.            (vlax-release-object sa)
  11.           )
  12.     )
  13.     (princ)
  14.   )
  15.   (_opendirectory (getvar 'dwgprefix))
  16. )

That is exactly the behavior I wanted!  Thanks!  Now I need to dig through some of my older code and switch to this.
Cheers!

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC