Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows服务启动和Exe_C#_Wpf_Windows Services - Fatal编程技术网

C# Windows服务启动和Exe

C# Windows服务启动和Exe,c#,wpf,windows-services,C#,Wpf,Windows Services,我目前正在从事一个包含WCF服务、Windows服务和WPF应用程序的项目。Windows服务与WCF通信,并且在特定情况下,必须启动WPF应用程序才能让用户接收消息。(WCF在远程服务器上,其余在客户端上)。我在发射时遇到了一点困难。我让服务将消息写入应用程序日志,这样我就可以在过程中进行某种程度的“调试”。Windows服务运行以下代码时没有问题 C#代码,Windows服务: WriteLog.WriteString("PostOffice.MessagesWaiting: Inside,

我目前正在从事一个包含WCF服务、Windows服务和WPF应用程序的项目。Windows服务与WCF通信,并且在特定情况下,必须启动WPF应用程序才能让用户接收消息。(WCF在远程服务器上,其余在客户端上)。我在发射时遇到了一点困难。我让服务将消息写入应用程序日志,这样我就可以在过程中进行某种程度的“调试”。Windows服务运行以下代码时没有问题

C#代码,Windows服务:

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;
messagingProcess.Start();
StreamReader daStreamReaderMan = messagingProcess.StandardOutput;
string newString = daStreamReaderMan.ReadLine();

WriteLog.WriteString("PostOffice.MessagesWaiting: The Eagle has landed.", EventLogEntryType.Warning);
WPF应用程序不在当前用户的会话中执行。相反,我会弹出一个窗口来查看消息。下面是它的图片:

一旦选择了“查看消息”选项,它当然会将我切换到另一个会话,然后运行WPF应用程序


我的问题是,我应该如何让WPF应用程序在当前用户的会话或“活动”会话中启动?

之所以这样,是因为尝试启动WPF可执行文件的用户没有与桌面交互的权限

Windows服务通常不在具有该权限的帐户下运行,这样做被视为安全漏洞

在大多数情况下,建议您不要更改“允许服务与桌面交互”设置。如果允许服务与桌面交互,则服务在桌面上显示的任何信息也将显示在交互用户的桌面上。然后,恶意用户可以控制该服务或从交互式桌面对其进行攻击


一个更安全的替代方案是让WPF应用程序始终在系统托盘中运行,并为Windows服务安排一种机制,向WPF应用程序发出需要显示消息的信号。一个简单的机制是将文件写入约定的位置,并使用WPF应用程序中的文件监视程序查找该文件(并在显示后将其删除)。请注意,windows服务可能在用户登录之前很久(WPF应用程序运行之前很久)就已运行,因此,无论您使用何种通知机制,都需要允许消息在登录后立即累积和显示。

Hi-“WCF服务”、“windows服务”和“WPF应用程序”都是完全不同的。更重要的是,它们都是完全不同的东西。是的,他们都可以互相交流:有很多方法可以做到这一点。是的,您可以进行设置,以便“事件”(例如,来自Windows服务的消息)可以触发“操作”(甚至可以在用户桌面上启动.exe)。但是不是:windows服务和WPF服务都存在于与用户桌面完全不同的上下文中。我认为你不能做你想做的事情。@paulsm4:默认情况下,它们存在于不同的环境中。确实可以授予windows服务与桌面交互的权限。这样做是不明智的。@AngieLeigh:现在你有10个积分:-)谢谢!我可能无法准确地使用这种方式,但肯定是沿着这种思路。再次感谢:-)