问题描述
我在 Windows 服务 (0) 会话中运行了一项服务.从客户端连接后,我需要为给定的用户凭据创建一个新的 Windows 会话,登录该用户并在此新会话中启动应用程序.
I have a service running in the Windows services (0) session.Upon connection from a client I need to create a new Windows session for given user credentials, log in that user and start an application into this new session.
有没有办法以编程方式为给定的用户凭据创建用户会话?
Is there a way to programmatically create a user session for given user credentials?
推荐答案
AFAIK,您不能以可编程方式创建会话.为此,客户端必须使用终端服务或远程桌面连接到计算机.但是,如果您只需要以该用户身份运行进程而不使其在屏幕上可见,您可以通过编程方式登录到用户帐户并模拟它.查看 LogonUser()
和 ImpersonateLoggedOnUser()
、CreateProcessAsUser()
或 CreateProcessWithLogonW()
.
AFAIK, you cannot create sessions programmably. The client would have to connect to the machine using Terminal Services or Remote Desktop for that. You can, however, programmably log in to a user account and impersonate it if you just need to run a process as that user without making it visible to the screen. Look at LogonUser()
and ImpersonateLoggedOnUser()
, CreateProcessAsUser()
, or CreateProcessWithLogonW()
.
这篇关于以编程方式创建 Windows 会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!