0

我想创建一个 Windows 服务,并能够通过获取上下文来模拟登录到框中的用户,可能是通过 getprocesses 函数或 ManagementObject 代码。

我没有密码,但用户将登录到运行服务的框。然后,此上下文将用于模拟。

4

1 回答 1

1

I'm not sure that what you want to do as described is possible. Without a password, you cannot impersonate another user, unless their is some sort of coordination between your service, and the user you want to impersonate.

This thread has good information about how to impersonate a user: How do you do Impersonation in .NET?

In order to impersonate the user, you need the Win32 user token. You usually get this via the Win32 LogonUser, which requires a password.

You can work around this however, by having the user that you want to impersonate to initiate a request with your service. You can do this via a start up task, manual user action, or other methods. If you are able to do this, you might want to consider us WCF to create your service. WCF allows you to configure your service to impersonate the user that is making the service call.

于 2013-06-24T18:11:45.903 回答