Page 1 of 1

Using everything SDK in IIS 7.5

Posted: Sat Dec 31, 2016 8:59 am
by AxeOfMen
I have written a Web API that is running in IIS 7.5 which uses the everything SDK to search for files. I have installed the 32 bit version of everything on the server running IIS and am using the 32 bit sdk methods. All is working fine on my development machine, but on the IIS machine, running the SDK from within a Web API application returns no search results. I've tried giving the web application admin privileges but still nothing.

This is the method I'm using to search:

Code: Select all

        protected IEnumerable<string> Search(string searchTerms)
        {
            List<string> results = new List<string>();
            const int bufsize = 260;
            StringBuilder buf = new StringBuilder(bufsize);
            everything32.Everything_SetSearchW(searchTerms);
            everything32.Everything_SetMatchPath(true);
            bool synchronous_query = true;
            everything32.Everything_QueryW(synchronous_query);
            everything32.Everything_SortResultsByPath();
            int resultCount = everything32.Everything_GetNumResults();
            for (int i = 0; i < everything32.Everything_GetNumResults(); i++)
            {
                int x = everything32.Everything_GetResultFullPathNameW(i, buf, bufsize);
                results.Add(buf.ToString());
            }
            return results;
        }
On my development machine the return value is populated with results. When run in IIS, the return value is empty.

Any thoughts?

Re: Using everything SDK in IIS 7.5

Posted: Sat Dec 31, 2016 10:52 am
by void
Is the Everything client running on the IIS server?

What is the return value from Everything_GetLastError?

Re: Using everything SDK in IIS 7.5

Posted: Sat Dec 31, 2016 4:04 pm
by AxeOfMen
Yes, "Everything.exe *32" shows up in the task manager as running.
The return value of Everything_GetLastError() is 4.

Re: Using everything SDK in IIS 7.5

Posted: Sun Jan 01, 2017 12:11 am
by void
Error 4 = Everything IPC is not available. (Should be error code 2, but it's a bug with the latest SDK)

Is the "Everything.exe *32" process the Everything service or the Everything search client?
Please try the same thing again with a Everything search window open in the background.

Re: Using everything SDK in IIS 7.5

Posted: Sun Jan 01, 2017 12:20 am
by AxeOfMen
With both the service and the search client running I get the same result (4).

The command lines displayed in the task manager are
"C:\Program Files (x86)\Everything\Everything.exe" -svc
"C:\Program Files (x86)\Everything\Everything.exe"

The service is running under the SYSTEM account and the client is running under my personal account (my account is an admin)

What I mean to say is that with the Everything search window open, I still get error 4.

Re: Using everything SDK in IIS 7.5

Posted: Sun Jan 01, 2017 12:56 am
by void
Does the ES command line interface utility work?

Re: Using everything SDK in IIS 7.5

Posted: Sun Jan 01, 2017 1:34 am
by AxeOfMen
No, the ES command line interface does not work when executed from within the web app. I get a similar response from it:
"Everything IPC window not found, IPC unavailable."
Exit code is 1

Here is the code I'm using to call it:

Code: Select all

        protected IEnumerable<string> SearchViaCommandLine(string searchTerms)
        {
            List<string> result = new List<string>();
            Process proc = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = @"c:\program files (x86)\Everything\es.exe",
                    Arguments = "-p " + searchTerms,
                    UseShellExecute = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow = true
                }
            };
            proc.Start();
            while (!proc.StandardOutput.EndOfStream)
            {
                string line = proc.StandardOutput.ReadLine();
                result.Add(line);
                Log("Result from es: " + line);
            }
            int stat = proc.ExitCode;
            if (stat != 0)
            {
                Log("Exit code from es: " + stat.ToString());
            }
            return result;
        }
This is with a search window open and the everything service running. ("Run as administrator" is also checked in options)

Re: Using everything SDK in IIS 7.5

Posted: Sun Jan 01, 2017 1:39 am
by void
What version of Everything are you using?

I'm wondering if it's a privilege issue, have you tried running Everything as a standard user?

Re: Using everything SDK in IIS 7.5

Posted: Sun Jan 01, 2017 1:50 am
by void
Is Everything running with a instance name?

Re: Using everything SDK in IIS 7.5

Posted: Sun Jan 01, 2017 1:53 am
by AxeOfMen
I'm using version 1.3.4.686 (x86)
There are two accounts on this windows server and both are administrators so running as a standard user isn't possible on this server, to my knowledge. (Though, if you mean have I unchecked "Run as administrator" in Everything options, then yes. I have tried that with no change in results)
Changing CreateNoWindow to false had no effect.
> Is Everything running with a instance name?
I'm not sure what you mean.

Re: Using everything SDK in IIS 7.5

Posted: Sun Jan 01, 2017 2:09 am
by AxeOfMen
I wrote a small console app to use the SDK and the ev tool. Both work as expected on the server from the console app.
The IIS worker runs in a different Terminal Server Session than normal applications so I don't think it can interact with the everything process running in my windows session, but I don't know why the ev tool can't work from within IIS.

Re: Using everything SDK in IIS 7.5

Posted: Mon Jan 02, 2017 9:27 am
by void
A couple ideas, try allowing the IIS service to interact with the desktop:

From the Start menu, under control panel, under administrative tools, click Component Services.
  • Click Services (Local) on the left.
  • Click the IIS service.
  • Click the Log On tab.
  • Click Allow service to interact with desktop.
  • Click OK.
  • Restart the service.
Try launching ES with different credentials (See UserName and Password in ProcessStartInfo).

Re: Using everything SDK in IIS 7.5

Posted: Mon Jan 02, 2017 5:27 pm
by AxeOfMen
Does es.exe require Everything.exe client to be running (with a window) and interacts with it via IPC?

Re: Using everything SDK in IIS 7.5

Posted: Mon Jan 02, 2017 7:13 pm
by void
Yes.

ES uses the Everything SDK which may make it easier to detect the issue.

Re: Using everything SDK in IIS 7.5

Posted: Mon Jan 02, 2017 7:39 pm
by AxeOfMen
Good news, I got it working by starting the everything.exe process first using `WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden`

My first attempt after that was to interact with es.exe to get the search results. It was necessary to run es.exe repeatedly *on my first attempt* because the everything.exe process was still in the process of launching and not completely ready for interactions from es.exe. This was ok. I simply repeated my request until I got a correct response which didn't take too long. Subsequent requests succeeded on the first attempt since everything.exe was functional and ready for requests.

Then instead of es.exe I switched to using the SDK. The SDK doesn't seem to have the same issue of failing the first request due to everything.exe being in an unready state. Can you clarify this for me? Does the SDK handle the case for me where everything.exe is unready and waits until it is ready? Or is this a fluke and I should still wrap my requests in a loop to try repeatedly until success/timeout?

Hmm, you said that es.exe uses the SDK, so I'm starting to think this was a fluke, but it seems to behave this way consistently. Curious.

Re: Using everything SDK in IIS 7.5

Posted: Tue Jan 03, 2017 5:28 am
by void
The SDK doesn't seem to have the same issue of failing the first request due to everything.exe being in an unready state.
The SDK will return no results if Everything is not in a ready state. The same as ES. ES has a -timeout <milliseconds> option to wait for the db to be in the ready state before sending the query (by default it is off).
You will need to check if Everything is ready with the SDK Everything_IsDBLoaded function or IPC EVERYTHING_IPC_IS_DB_LOADED call.
Or is this a fluke and I should still wrap my requests in a loop to try repeatedly until success/timeout?
Put your SDK calls in a loop and check for Everything_IsDBLoaded / IPC EVERYTHING_IPC_IS_DB_LOADED before calling Everything_Query. At the start of the loop check for some timeout, see the ES source code for implementation.

Re: Using everything SDK in IIS 7.5

Posted: Wed Jan 04, 2017 3:25 pm
by AxeOfMen
Thanks for the feedback. I do not see Everything_IsDBLoaded documented nor can I find its use in the source code of ES. I tried the following but it always returns false:

Code: Select all

[DllImport("Everything32.dll")]
public static extern bool Everything_IsDBLoaded();
Edit: I'm looking at the source code located here: https://www.voidtools.com/es-src.zip

Re: Using everything SDK in IIS 7.5

Posted: Wed Jan 04, 2017 10:05 pm
by void
ES calls EVERYTHING_IPC_IS_DB_LOADED directly.

Everything_IsDBLoaded / IPC EVERYTHING_IPC_IS_DB_LOADED only works if your are running Everything 1.4.1 or later.

Prior to Everything 1.4.1 there is no way to check if Everything is ready.