How does Everything launches files?

General discussion related to "Everything".
Post Reply
V@no
Posts: 39
Joined: Sat Sep 04, 2010 1:57 pm

How does Everything launches files?

Post by V@no »

Hello.
When you double click on a file from Everything window, it opens it in default application (if available).
My question is, internally, what command does Everything use to launch a file?

The reason I'm asking, is because so far Everything is the only application that can open .dwg files in the already opened Autocad 2002 instead of launching in a new window, i.e when I try open .dwg file from explorer it launches Autocad as a new window

Perhaps knowing how Everything does it, I'll be able come up with my own launcher...

Thank you.
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: How does Everything launches files?

Post by NotNull »

There are quite a few reasons why Everything starts a different program/ a program in a different way compared to Explorer:
- you are running Everything as administrator
- You are running 32 bit Everything on a 64 bit Windows
- You are running Windows 10 (or maybe Win8; don't know much about Win8)

Without further details, it's too much work zooming in on all possibilities.
V@no
Posts: 39
Joined: Sat Sep 04, 2010 1:57 pm

Re: How does Everything launches files?

Post by V@no »

Well, I've tried it with an elevated command prompt, via elevated autoit script (that's pretty much the highest level of programming for me), in all cases it always launches separate process.

Here is some details:
Running Everything 64bit as administrator on Windows 10 Pro

Launching AutoCAD 2002 32bit as administrator, which was made for Windows XP, hens it only works when elevated.

In task manager the command line for Acad launched by Everything shows exactly the same as when I launch it via CMD/autoit script:

Code: Select all

"C:\Acad\acad.exe" "C:\drawing.dwg"
So there must be something different the way Everything launches it.
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: How does Everything launches files?

Post by NotNull »

That's a lot of useful information. Thanks!

First step:
Make sure your 'regular' acad.exe and the one you start from Everything are running under the same credentials ( usernames).
Otherwise they will run in different 'rooms' and can't talk o each other (and thus will start a separate process, instead of attaching to an already running acad.exe.

Do you start your 'regular' AutoCAD through a shortcut? What happens if you start this shortcut from Everything?


Oops, read it wrong ...

If you run a .DWG from an Everything session that is running as administrator, it will attach to an already running AutoCAD that is also running as administrator.
If you start that .DWG from Explorer (which is NOT running as administrator), you will start an acad.exe that is running under your normal credentials.
Those 2 can't talk to each other as they live in separate spaces..

2 solutions/workarounds:
  • Run ACAD.exe always as administrator:
    • In Explorer, browse to ACAD.exe
    • Right-click > Properties > Compatibility tab > enable Run this program as Administrator
  • Change the default verb for .dwg files
    This option is less recommended (as you have to do this for all AutoCAD related file extensions, but if you want to go this route, I will provide instructions
BTW: Not tested ....
V@no
Posts: 39
Joined: Sat Sep 04, 2010 1:57 pm

Re: How does Everything launches files?

Post by V@no »

I only have one user on this system, so there shouldn't be any user conflicts here

I'm not actually launching acad.exe itself from Everything, I'm launching a .dwg file that is associated with acad.exe.
It doesn't matter if I launched acad.exe myself from a shortcut (or directly via explorer) or I launch a .dwg file from explorer, it popups up UAC prompt and opens a new acad window, even if there is already one opened.

With Everything on other hand, since it's running as administrator (elevated) it doesn't show UAC prompt when I double click on .dwg file, it opens it in existing acad.exe window or launches one if it's not launched yet.

[EDIT]
After typed all this, I found why it didn't work for me in CMD - because I was actually launching acad.exe with a path to .dwg as argument.
However once I've tried execute just the .dwg file

Code: Select all

start C:\drawing.dwg
it worked like charm.

Thank you for your time!
void
Developer
Posts: 16773
Joined: Fri Oct 16, 2009 11:31 pm

Re: How does Everything launches files?

Post by void »

Currently, Everything uses ShellExecuteEx with SEE_MASK_IDLIST to open files and folders.
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: How does Everything launches files?

Post by NotNull »

NotNull wrote: Tue Dec 04, 2018 7:49 pm - You are running Windows 10 (or maybe Win8; don't know much about Win8)
void wrote: Wed Dec 05, 2018 9:34 am Currently, Everything uses ShellExecuteEx with SEE_MASK_IDLIST to open files and folders.
Since Window 10 (and probably Win8), regular file associations are 'deprecated' (not the right word, but that's the best I got right now)
That's because Microsoft wants to prevent applications 'stealing' file extensions to protect the user.

Instead of that (*), there is now a UserChoice registry entry. The choice of the user can not be tampered with (includes a hash to check it's integrity) after it has been set.
Those keys can be found under HLCU\software\microsoft\windows\currentversion\explorer\FileExts.

(This version of) ShellExecuteEx does not 'honor' the UserChoice settings.

(Not that I mind; just a FYI)

(*) Not completely accurate .. If there is no UserChoice setting, the normal file associations are used; If there is a UserChoice setting, that one supersedes.
V@no
Posts: 39
Joined: Sat Sep 04, 2010 1:57 pm

Re: How does Everything launches files?

Post by V@no »

Thank you very much for the explanation.

I know this is wrong place to ask, but perhaps you might know, how does Windows opens files with associated executable? I mean is there a way "emulate" association and open a file with executable as if they were associated?
I mean does Windows sends some kind of command to already running executable to open a file, or something in that nature?

In my tests, using ShellExecuteEx to launch an executable with a path to a file as command line parameter, just launches a new process instead of open in already running executable.
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: How does Everything launches files?

Post by NotNull »

V@no wrote: Fri Dec 14, 2018 6:42 pm I know this is wrong place to ask, but perhaps you might know ...
I don't know which "you" you are referring to, but maybe this might help in understanding. And if not: just ask and I (or anyone else here) might be able to help you further.
void
Developer
Posts: 16773
Joined: Fri Oct 16, 2009 11:31 pm

Re: How does Everything launches files?

Post by void »

From what I can see, Windows Explorer invokes the default command from the context menu when "Opening" file(s).
This default command is called once on an object describing all selected files.

I've been experimenting with this and may add optional support to do this in a future release.
Whether it will running the default command once on all selected objects, or running the default command on each individual object, or both..
V@no
Posts: 39
Joined: Sat Sep 04, 2010 1:57 pm

Re: How does Everything launches files?

Post by V@no »

NotNull wrote: Sun Jul 15, 2018 8:17 pm Even the $exec("%1") makes (implicit) use of the verb-mechanism.

Here's what happens if you double-click the Myfile.txt file in Everything:
(simplified; there are exceptions and there is a lot more to it; but to get the idea..)
  • Everything asks Explorer (the shell) to execute C:\path\myfile.txt
  • Explorer looks in the registry to find out what to do with .txt files (HKCR\.txt)
  • and finds it can find details about that under the (default) key txtfile
  • Looking under HKCR\txtfile\Shell it looks if there is a verb defind under (default).
  • If so (let's say it found the verb "dummy"), execute what is under HKCR\txtfile\shell\dummy\command
    But there is no "dummy" defined, so time for the next step:
  • If there is an "Open" verb under HKCR\txtfile\shell\, find out what program to run under HKCR\txtfile\shell\Open\command.
  • On my system it says: %SystemRoot%\system32\NOTEPAD.EXE %1 (whre c":\path\mufile,txt will be substituted for %1)
  • Explorer (shell) will execute c:\windows\system32\NOTEPAD.EXE "c:\path\myfile,txt"
  • If there is no Open verb defined, it will execute the command that is configured for the alphabetically first verb (see .ttf for an example)
    (BTW: the entries in the context menu are alphabetically sorted by verb)
void wrote: Sat Dec 15, 2018 3:08 am From what I can see, Windows Explorer invokes the default command from the context menu when "Opening" file(s).
This default command is called once on an object describing all selected files.

I've been experimenting with this and may add optional support to do this in a future release.
Whether it will running the default command once on all selected objects, or running the default command on each individual object, or both..
Here is a weird thing; AutoCAD 2002 was made during XP era, and requires administrative rights to run (probably because it writes into HKLM registry and HKCS) Anyway, on Windows 7 with UAC disabled it runs perfectly fine, .dwg files launched from explorer open in tabs of already running Acad window.
On Windows 8/10 even with UAC disabled it starts new process (new window), however with elevated Everything it opens in tabs. My guess here, since W8/10 doesn't give user 100% administrative rights with UAC off, explorer still runs in somewhat protective mode that doesn't allow it access high privileged processes(?)

So, if explorer (shell) executes the default command for .dwg file when such file opened from Everything, then theoretically if an elevated application execute same exact command it should open the file in already running process. However in my experiments with elevated command prompt it doesn't work, it launches new process instead. So there is must something else involved.

Looking into registry for .dwg file, it has standard default command "C:\AutoCAD 2002\acad.exe" "%1" however there is another key: ddeexec with default value [open("%1")]. Perhaps that is the key here...8-)
void
Developer
Posts: 16773
Joined: Fri Oct 16, 2009 11:31 pm

Re: How does Everything launches files?

Post by void »

AutoCAD is using dynamic data exchange (DDE) for Inter Process Communication (IPC).

If you are launching a dwg from Everything or Windows Explorer as a standard user, User Interface Privilege Isolation (UIPI) will prevent a new instance of AutoCAD communicating with the already running instance of AutoCAD via DDE.
V@no
Posts: 39
Joined: Sat Sep 04, 2010 1:57 pm

Re: How does Everything launches files?

Post by V@no »

Thank you very much! DDE was the answer. I got a 100% working launcher now
Post Reply