1

I have two applications:

  • UpdaterService.exe (Windows Service)
  • Updater.exe (UI application)

I want to achieve, that my Windows Service calls my UI application. I tried:

Process p = new Process();
p.StartInfo.FileName = completePath;
p.StartInfo.WorkingDirectory = workingDirectory;
p.Start();

This works, but when I calls a UI element (e.g. MessageBox) I get an InvalidOperationException.

I can do:

p.StartInfo.UserName = userName;
p.StartInfo.Password = password;

but I don't have credentials for every user so that's out of the question.

Since Windows Vista and the Session 0 Isolation, I understand that every process, which is called by a Windows Service also runs in Session 0 and can't have a UI.

I read all articles to this theme I found, and I found this article, which describes my problem. It uses the Win32-API, get the actual user ID from winlogon.exe and opens the exe. I didn't tried it yet, but I guess it works (even in Win 7/10).

My Service and UI application don't need any kind of communication, it just should call the exe with the actual user account which is logged in.

I think it's not so uncommon to open a UI-exe from a service, because other companies (like Adobe) does the updates in the same way.

My questions are: Is it a 'clean way' to use the Win32 and subverting the Session 0 security (the updater will run only on Windows OS)? Is there meanwhile a better way to achieve this with .Net framework?

Beetee
  • 475
  • 1
  • 7
  • 18
  • Search for WTSQueryUserToken, there are a number of existing questions on the subject. – Harry Johnston Feb 11 '17 at 00:44
  • @Harry: Did you read my questions at the end? I know the functionality of Win32 API... – Beetee Feb 13 '17 at 08:19
  • As a workaround (this is the most 'clean way' I know) you can run a windows task that run the UI process. – zvi Feb 13 '17 at 10:19
  • You didn't seem to be aware of WTSQueryUserToken, since you never mentioned it. At any rate, that's almost certainly the way to go. Stealing a token from `winlogon.exe` is unsupported and doesn't do what you want anyway. Using a task is supported but awkward. Only WTSQueryUserToken provides a clean, supported, straightforward solution. – Harry Johnston Feb 13 '17 at 20:33
  • @Harry: Ok, thx. I thougt WTSQueryUserToken was used in the link I posted. I will take a look at this function. – Beetee Feb 21 '17 at 08:32
  • I solved with [this solution](http://stackoverflow.com/a/4147868/3757210): it is a very simple class! – ilcorvo Mar 09 '17 at 14:58

0 Answers0