Command line interface ES cannot talk to Everything if run from a scheduled task

If you are experiencing problems with "Everything", post here for assistance.
Post Reply
pistacho
Posts: 2
Joined: Sat Feb 23, 2019 7:21 pm

Command line interface ES cannot talk to Everything if run from a scheduled task

Post by pistacho »

Hello,

I've downloaded Everything v1.4.1.935 (x64) and installed it as a service, from a regular user (non administrative) account on a Windows 10 Pro machine.

I've also downloaded its command line interface ES v1.1.0.10, and unzipped it at C:\test

If I launch an elevated (run as Administrator) command line window (cmd.exe), and then I type the following:

Code: Select all

C:\test\es.exe -export-csv C:\test\txt.csv *.txt
I get a file named C:\test\txt.csv which contains a list of every TXT file, as expected.

However, if I run the task scheduler as Administrator and create a scheduled task where I define an action to run the very same command I previously mentioned, then ES creates a CSV file which only contains the header (one line that says Filename).

If I create a batch file with that command, and run that BAT as an action of my scheduled task, I only get the Filename header again.

Finally, if I create a batch file with this command:

Code: Select all

C:\test\es.exe *.txt > C:\test\txt.csv
and run that BAT as an action of my scheduled task, then the content of C:\test\txt.csv is one line that says:

Code: Select all

Everything IPC window not found, IPC unavailable.
However, if I dig on the Everything.ini files there's a line that says

Code: Select all

ipc=1
Which was expected, as when I run the ES tool manually it actually does find the TXT files.

The results don't change despite I've tried to modify all the setting of the scheduled task: checking and unchecking the "Run with highest privileges" checkbox, checking and unchecking the "Hidden" checkbox, etc.

I've found that if I launch Everything from the batch file then ES works perfectly, but this leaves Everything.exe running, and the task never gets finished on the scheduler.

Could someone please tell me what is the proper way to run ES from a scheduled task?

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

Re: Command line interface ES cannot talk to Everything if run from a scheduled task

Post by NotNull »

First of all: thank you for a very thorough description of your issue! Makes finding an answer a lot easier..

ES.exe needs Everything.exe running, as it passes your search request to Everything.exe, which in return will look in it's database and pass the matching results back to ES.exe.

So a script that:
- starts Everything
- Executes your ES command
- Ends Everything.exe

should do the job. But ....


When Everything is started, the first thing it does is updating it's database with new changes to the filesystem since Everything ran for the last time.
During this update process, Everything is not able to process your ES.exe command.
There is no easy way to know when Everything is done updating, but it is doable with a little workaround:

Code: Select all

"c:\path to\Everything.exe" -startup & start /w "" "c:\path to\Everything.exe" -update
C:\test\es.exe -export-csv C:\test\txt.csv *.txt
"c:\path to\Everything.exe" -quit
(not tested, btw)

For a little background information, see viewtopic.php?t=6632


Note:
This is step 1, as this will also quit your "normal" Everything program. Solution to that is using a separate instance.
But let's see first if this comes a bit closer to your goal.
pistacho
Posts: 2
Joined: Sat Feb 23, 2019 7:21 pm

Re: Command line interface ES cannot talk to Everything if run from a scheduled task

Post by pistacho »

Thank you very much for your quick response!

I forgot to say that I had also tried to install the Everything client service (and start it), but my results where the same.

Your solution works perfectly. Curiously enough the batch of the scheduled task initiates another Everything.exe process (which doesn't conflict with the one that the regular user may already be running), and it gets closed when the batch invokes the -quit parameter (while the regular user Everything.exe process keeps running). So there's no need to use instances in this particular case.

Thank you very much!

However, I don't understand why the elevated command prompt ES execution (which runs as the Administrator user) does see the regular user Everything.exe process so it can use IPC to query the database, but the batch from the scheduled task (which is also supposed to run as Administrator) cannot talk to so it needs to launch its own Everything.exe process. Do you know why does this happen?

Thank you again.
therube
Posts: 4985
Joined: Thu Sep 03, 2009 6:48 pm

Re: Command line interface ES cannot talk to Everything if run from a scheduled task

Post by therube »

(Guessing, I'd say the scheduled task is actually running at a different privilege level?)
void
Developer
Posts: 16841
Joined: Fri Oct 16, 2009 11:31 pm

Re: Command line interface ES cannot talk to Everything if run from a scheduled task

Post by void »

Everything and ES use ChangeWindowMessageFilterEx to allow each other to communicate between administrator and standard user and vice versa.

However, if you create a scheduled task with a different user that is not logged in, then that task will run in a new session and will not be able to access the Everything IPC window.

For example, if you are logged in as a standard user, and create a scheduled task to run with a administrator user account, the task will run in a different session.

Programs can not use windows to communicate between different sessions.

Please make sure the scheduled task runs as the same user that is currently logged in.
Please make sure Run only when user is logged on is checked.
Please check Run with highest privileges if you want ES to run as administrator. However, please note if you want to enable this you will need to run Scheduled Tasks as an administrator.
Zeitgeist
Posts: 5
Joined: Mon Feb 07, 2022 5:57 pm

Re: Command line interface ES cannot talk to Everything if run from a scheduled task

Post by Zeitgeist »

I also would like to run everthing.exe > do the indexing > run es.exe > quit everything.exe via a scheduled task.
I created a scheduled task and set up three actions in it (see screenshot).
screenshot.jpg
screenshot.jpg (39.53 KiB) Viewed 4421 times

When the scheduled task is started:
  • the everything "command line options" help screen pops up.
  • for half a second a black cmd window flickers
  • an empty "result.txt" is created.
If I put all lines in a single batch file and run it manually, a cmd window appears, shoing the first line "D:\everything\everything.exe -startup & start /w "" D:\everything\everything.exe -update", then nothing more happens - like the window is freezed.

If I run the es.exe command separately, while everything.exe running in the background, a correctly filled result.txt is created.

I don´t know how to solve this, can you please give me a hint?


PS.
I don't know if it is important, but I run the scheduled task in a normal user context (not as an admin). To archive results, I deactivated "run as administrator" and deactivated indexing for all drives. I included just one folder (c:\test) for indexing which is also located on a NFTS drive but indexing as a user seems to work.
NotNull
Posts: 5461
Joined: Wed May 24, 2017 9:22 pm

Re: Command line interface ES cannot talk to Everything if run from a scheduled task

Post by NotNull »

D:\everything\everything.exe -startup & start /w "" D:\everything\everything.exe -update"

.. is something the task scheduler does not understand. The & is there to separate commands in CMD/batch files. It has no meaning in the shell/task scheduler.

Option 1:
Put all these command in a CMD file, like GetMyList.cmd and define the action c:\myfolder\GetMyList.cmd


Option 2:
In the meantime there is a better way: ES.exe now supports the -timeout parameter. That makes ES wait until the database is loaded and available. It doesn't wait the entire 99999 milliseconds; just long enough for Everything to become available.
With that:
Action 1 = D:\everything\everything.exe -startup
Action 2 = D:\everything\es.exe -timeout 99999 c:\test .....
Action 3 = D:\everything\everything.exe -quit
Zeitgeist
Posts: 5
Joined: Mon Feb 07, 2022 5:57 pm

Re: Command line interface ES cannot talk to Everything if run from a scheduled task

Post by Zeitgeist »

To avoid any issues with UAC, I now used an admin account for testing, tuned on indexing of drive c and "run as administrator".
"Store settings and data in %APPDATA%everything = OFF
I doubble checked, if I use the newest version of everything.exe and es.exe.
And I tested everything, one time with all the files and executables located on d:\ and one time on c:\ - in both cases, the results were identical.


First I tried to run the commands (as you told me) as a *.bat file:

Code: Select all

C:\everything\everything.exe -startup
C:\everything\es.exe -timeout 99999 c:\test -regex  S[0-9][0-9][0-9][0-9][0-9][0-9] -export-txt C:\everything\result.txt
C:\everything\everything.exe -quit
When I do so, the following happen:
  1. A UAC dialog pops up, asking if I realy want to execute everyting.exe. I have to confirm it manually.
  2. A cmd window, showing "D:\everything\everything.exe -startup" pops up and stays in focus.
  3. The Everynote icon appears in system tray (no everything.db is created in the everynote folder)
  4. nothing happens any more
  5. I set the timeout to 999, ran it again, but it did not change the behaviour of the points 1-4 in any way.
  6. If I manually exit everything.exe...
    ...a everything.db appears in the everynote folder
    ...the cmd window shows the es.exe command, which terminates because everynote.exe is not running (obviously)
    ...a empty "result.txt" was created
  7. A UAC dialog pops up, asking if I realy want to execute everyting (I think it is the "-quit" command). I have to confirm it manually.
So this does not work for me.

Second: If I enter the mentioned commands in a scheduled tast and run the task: nothing happens.
No tray symbol, no everything.exe in process explorer, nothing.
Only the status of the scheduled task changes to "running".
I have to manually quit the scheduled task.
So also this is not working for me.

Any more ideas?
Zeitgeist
Posts: 5
Joined: Mon Feb 07, 2022 5:57 pm

Re: Command line interface ES cannot talk to Everything if run from a scheduled task

Post by Zeitgeist »

The "timeout" function would be nice, but it did not work on my system and in any way I tried setting it up.

So I found out a workaround for this by myself.

Here it a description what the batch file below is doing:
  1. It deletes any everything.db file.
  2. Then it starts the everything.exe, waits 1 second and then kills it right away.
  3. Why killing it? Because this creates the apparently only way to get a external visibe sign, that the indexing has ended.This is, because the everything.exe seems to immediately create a sub-process to do the indexing after its start. That sub-process is not be killed by the "taskkill" command.
  4. So, that sub-process creates eventually a "fresh" everything.db in the program folder.
  5. The batch waits for the "fresh" everything.db to exist.
  6. If it exists, it stats the everything.exe again and without waiting for the now running new indexing it runs my wanted es.exe command.
  7. So the es.exe uses the DB, that was build just a few moments before and it does not have to wait till the now running indexing has finished.
  8. When the es.exe has finished its job, it kills the everything.exe.
Thats it. Here is the batch file, that worked for me.

Code: Select all

@ECHO OFF
del /f "Everything.db"
start everything.exe -startup
TIMEOUT /T 1 >nul
taskkill /IM "everything.exe"

SET LookForFile="C:\everything\Everything.db"

:CheckForFile
IF EXIST %LookForFile% GOTO FoundIt
TIMEOUT /T 3 >nul
GOTO CheckForFile

:FoundIt
start everything.exe -startup
TIMEOUT /T 5 >nul
c:\everything\es.exe <enter your commands here>
c:\everything\everything.exe -quit
exit
By the way: I was not able to set up a working scheduled tast, until I run not the batch directly as an action, but the "c:\windows\system32\cmd.exe" with the wanted batch file as an argument.

Now the scheduled task was working, but it created a visible CMD window, every time it runs. I do not like that. To avoid that, I used the first method mentioned here.

I hope this helps others to spend less time to find a solution.
void
Developer
Posts: 16841
Joined: Fri Oct 16, 2009 11:31 pm

Re: Command line interface ES cannot talk to Everything if run from a scheduled task

Post by void »

Please try the following bat file:

Code: Select all

@ECHO OFF

REM use -no-db to start Everything without a database from disk
REM this will create an in-memory database only (forcing a fresh reindex)
REM use -instance "scheduled task" so this task doesn't interfere with the normal Everything instance.
REM use -startup to prevent showing any search windows.
START "" Everything.exe -instance "scheduled task" -startup -no-db

REM call es with your search and set a timeout value of 5 minutes.
REM ERRORLEVEL is set to 8 if this call times out.
es.exe <Your ES Search here> -instance "scheduled task" -timeout 300000

REM Tell Everything to quit
Everything.exe -instance "scheduled task" -quit
Post Reply