c#中的Windows服务只能为当前用户运行吗? [英] Can a windows service in c# run only for current user?

查看:283
本文介绍了c#中的Windows服务只能为当前用户运行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果系统中有多个用户,那么每个用户的Windows服务可以单独启动吗?这可能吗?

If there are multiple users in a system then for each user windows service can be separately started? Is this Possible?

推荐答案

没有。服务在他们自己的帐户下运行,并在任何用户登录之前启动。



此外,Windows可以让多个人同时登录,所以它有点非常虚拟要求让服务冒充谁在控制台登录。



您的要求并未描述服务,而是一个启动的服务用户登录时注册表运行键。
No. Services run under their own account and start before any user ever logs in.

Also, Windows can have multiple people logged in that same time, so it's kind of a very screwy requirement to have a service impersonate whoever is logged in at the "console".

You requirement doesn't describe a service, but an application that launches out of the Registry Run key when a user logs in.


不,这违反了服务的整体思路。 Windows服务是一种可以独立于用户工作的应用程序。它可以在没有任何桌面的情况下工作,在所有用户注销时继续执行,如果配置为自动启动,则会在任何用户登录之前发生。



同时,Windows Server与某个帐户相关。其行为(授予应用程序的权限)取决于归因于服务安装的用户帐户。通常,这是特殊帐户之一(最常见的是网络服务,本地系统或本地服务),但它也可以作为常规交互式用户登录,在这种情况下,它应该是给出用户的密码。使用某个交互式用户的帐户进行服务登录不是理想的做法。



当然,服务可以检测不同的系统事件,例如用户登录和注销,通过某些交互式应用程序与当前用户通信等。这不是典型的或预期的行为;我不认为这与你的问题有关。目前尚不清楚为什么你对这种奇怪的事情感兴趣。如果你解释了你的最终目标,你可能会得到一些有用的实用建议。



-SA
No, this is against the whole idea of the service. A Windows Service is an application which can work independently of the users. It works without any desktop, will continue to execute when all users log off, and, if it is configured for auto-start, it happens before any users log on.

At the same time, a Windows Server is related to some account. Its behavior (permissions granted to the application) depends on the user account attributed to the service installation. Usually, this is one of the "special" account (most typically "Network Service", "Local System" or "Local Service"), but it can also log as a regular interactive user, and, in that case, it should be given a password of the user. Using an account of some interactive user for a service logon in not a desirable practice.

And of course, a service can detect different system events, such as user login and log off, communicate with the current user through some interactive application, and the like. It would not be a typical or intended behavior; and I don't think this is related to your question. It is not clear why are you interested in such a weird thing. It is possible that you could get some useful practical advice if you explained your ultimate goals.

—SA

这篇关于c#中的Windows服务只能为当前用户运行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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