How to make windows service interactivity with desktop application

LAI TOCA
2 min readApr 22, 2019

--

For some scenario we would wish our windows service that running under background, but communicate with desktop application for any purpose, for instance pop-up window for notice user that alarm something or…

Unluckily, windows OS (since Vista) was default disabled and disallowed this behavior for windows service to interactive with desktop application. So we need do a little tricky on it.

As per investigated, if we used Process.Start to invoke separate process in windows service was invalid due to the service process (system level) always stay in session 0. User process should be outside the session 0. This might case isolation problem for interactivity between user and service application.

After research more article for the session 0 isolation that point out use native Win32 Api (CreateProcessAsUser) might be workaround for the issue. So we took an experiment on it. Let’s start created process handler that using this approach:

The key point was to created process using CreateProcessAsUser, first we need create token from the user logged’s session. Through this method, we could finally communicated our windows service and desktop application that escaped from session 0 isolation:)

Note-1, if you got error message: privilege not held by client, please make sure your service was logged on as Local System account for grant the desired permission

Note-2 this approach not working under remote desktop, if you need deal with remote desktop environment, maybe you could try this reference.

Reference

--

--

LAI TOCA

Coding for fun. (Either you are running for food or running for being food.)