Windows服务启动和EXE [英] Windows Service launching and Exe

查看:281
本文介绍了Windows服务启动和EXE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在制作一个包含WCF服务,一个Windows服务和WPF应用程序的项目。 Windows服务的WCF连通,并在一定的情况下,必须启动为用户接收消息WPF应用程序。 (WCF是一个远程服务器上,其余的是在客户端上)。我已经打了一下,推出一个障碍的。我写邮件到应用程序日志的服务,让我可以在一定程度沿途调试。 Windows服务运行,没有任何问题下面的代码。

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#代码,Windows服务:

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

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



在WPF应用程序不能在当前用户的会话中执行。相反,我得到一个弹出来查看邮件。下面是它的照片:

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:

在选择查看信息选项,它当然切换我到不同的会话,然后运行WPF应用程序。

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

我的问题是,我应该怎么去获得WPF应用程序的当前用户的会话中启动,或主动会议?

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

推荐答案

您收到此,因为正在尝试推出WPF的可执行文件没有权限与桌面交互用户。

You are getting this because the user that is trying the launch the WPF executable does not have permission to interact with the desktop.

Windows服务通常不具有该权限的帐户下运行,并且它被认为是一个安全漏洞这样做。

Windows Services typically do not run under an account with that permission, and it is considered a security vulnerability to do so.

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

In most cases, it is recommended that you not change the Allow service to interact with desktop setting. If you allow the service to interact with the desktop, any information that the service displays on the desktop will also be displayed on an interactive user's desktop. A malicious user could then take control of the service or attack it from the interactive desktop.

http://technet.microsoft.com/en-us/library/cc782435(v = WS 0.10)的.aspx

一个更安全的替代将是有WPF应用程序始终在系统托盘中运行,并安排Windows服务机制预示着需要显示的消息WPF应用程序。一个简单的机制是将文件写入到约定地点,并使用一个文件看守在WPF应用程序查找该文件(并显示后删除)。请注意,Windows服务可能会被前(这么长时间的WPF应用程序正在运行之前)用户登录长期运行的,所以无论通知机制,您使用的需求,以允许邮件堆积并登录后立刻显示出来。

A more secure alternative would be to have the WPF application always run in the system tray and arrange a mechanism for the Windows Service to signal the WPF application that a message needs to be shown. One simple mechanism is to write a file to an agreed location and use a file watcher in the WPF app to look for that file (and delete it after displaying). Note that the windows service might be running long before a user logs in (so long before the WPF app is running), so whatever notification mechanism you use needs to allow for messages to accumulate and be displayed at once after login.

这篇关于Windows服务启动和EXE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆