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?