Sam Sippe
Sam Sippe

Reputation: 3190

3rd Party Application Fails when run from Service

I am trying to build a windows service that automates the running of an 3rd party application, let's call it BlackBox.exe. BlackBox.exe runs fine when run from the current user's session but fails when executed from the service. BlackBox.exe has a UI but it can be automated by passing it command line parameters. In the automated mode it shows some UI, reads input files, writes output files and then exits without any user interaction. We only have binaries for BlackBox.exe.

The service is configured to use the same user as BlackBox.exe was installed and registered under.

I've run a comparison of a the events captured by Process Monitor interactive session vs service session. There's no registry or file operations that are failing for the service session and succeeding for the service session. Notably, the registry keys for the license activation are read successfully in both cases.

When run from the service BlackBox.exe is visible in the Task Manager with 0% cpu and will remain there until killed.

I guess the lack of access to the desktop is causing BlackBox.exe to fail - maybe there's a way to fool BlackBox.exe to think it has access to the desktop without having a user logged in?

How can I run BlackBox.exe from a service?

UPDATE: If I:

...it works fine. So it might be related to Session 0 isolation

Upvotes: 2

Views: 252

Answers (1)

Eric Hirst
Eric Hirst

Reputation: 1161

Can you essentially run a popup blocker against this? The assumptions here are that that CloseMainWindow() will have the same effect as "View Message", and that you allow the service to interact with the desktop. Sample code below; adapt to your particular scenario and run as a separate thread from your service.

public class Program
{
    public static void Main(string[] args)
    {
        while (true)
        {
            DestroyAllBobs();
            Thread.Sleep(100);
        }
    }

    private static void DestroyAllBobs()
    {
        Process[] bobs = Process.GetProcessesByName("robert");
        foreach (Process bob in bobs)
        {
            if ("Microsoft Visual C++ Runtime Library".Equals(bob.MainWindowTitle))
            {
                bob.WaitForInputIdle();
                if ("Microsoft Visual C++ Runtime Library".Equals(bob.MainWindowTitle)
                    && "robert".Equals(bob.ProcessName))
                {
                    try
                    {
                        bob.CloseMainWindow();
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
    }
}

Upvotes: 1

Related Questions