Click here to Skip to main content
15,745,574 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am currently working on a project that contains a WCF service, a Windows service and a WPF application. The Windows service communicates with the WCF, and under a certain circumstance, must launch the WPF application for the user to receive messages. (WCF is on a remote server, the rest is on the client). I've hit a bit of a snag with the launch. I have the services writing messages to the application logs so that I can somewhat 'debug' along the way. The Windows service runs the following code with no problems.

C# code, Windows Service:

WriteLog.WriteString("PostOffice.MessagesWaiting: Inside, starting up.", EventLogEntryType.Warning);
// Call the WPF Application
var messagingProcess = new Process();
var messageProcessStartInfo = new ProcessStartInfo(@"""C:\GoldenEyeMessages.exe""");
messageProcessStartInfo.CreateNoWindow = false;
messageProcessStartInfo.UseShellExecute = false;
messageProcessStartInfo.FileName = @"""C:\GoldenEyeMessages.exe""";
messageProcessStartInfo.WindowStyle = ProcessWindowStyle.Normal;
messageProcessStartInfo.Verb = "runas";

messageProcessStartInfo.RedirectStandardOutput = true;
messagingProcess.StartInfo = messageProcessStartInfo;
StreamReader daStreamReaderMan = messagingProcess.StandardOutput;
string newString = daStreamReaderMan.ReadLine();

WriteLog.WriteString("PostOffice.MessagesWaiting: The Eagle has landed.", EventLogEntryType.Warning);

The WPF application doesn't execute in the current user's session. Instead, I get a popup to view the message. Here is a picture of it:[^]

Once selecting the 'View the message' option, it of course switches me to a different session and then runs the WPF application.

My question is, how should I go about getting the WPF application to launch within the current user's session, or the 'active' session?

Thanks for any help!

// Just as a side note, I have done quite a few hours of research on this and understand that this is a security risk (shatter attacks, replacing the exe, etc...) but this has been accepted by my employer for this current situation.
// I noticed that supposedly Windows Vista OS and later doesn't allow communications with user accounts because of the security issues, but it does have the ability to impersonate users... I'm thinking that might be an option to look in to...
Updated 18-Jul-12 9:26am

Bypassing Session 0 isolation[^] is not really possible[^] as I know. Impersonating a user does not mean that you get access to it's session.
Is the service really necessary, isn't enough to make the client start trayes on logon?
Or if you can not modify the client, you could make a fourth component start at logon, register to the service as listener and call the client on demand in the user session.
Share this answer
AngieLeigh 20-Jul-12 12:52pm    
Yes it has to be a service because of the main function of the program. Calling an external executable is just a small portion of it.
I have the same question, did you find the solution for this?
Share this answer
Bernhard Hiller 13-Aug-14 2:55am    
That is NOT an answer!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900