如何使用 C# 以编程方式切换用户

问题描述:

我有 Windows 2003 服务器,想使用 c# 以编程方式切换用户.我有所有活动用户的列表,那么如何切换用户?

I have windows 2003 server and want to switch users programatically using c#. I have list of all active user so how can I switch the user ?

我需要捕获当前登录的所有用户的屏幕.

I need to capture the screen of all users which are logon currently.

谢谢拉克斯米尔

您想要实现的目标并不完全清楚.

It is not entirely clear what you want to achieve.

有几种方法可以让程序以与登录用户不同的用户身份运行(或者让程序使用不同的凭据执行另一个进程):

There are several ways to have a program run as a different user than the logged in one (or have the program execute another process with different credentials):

  • 使用runas,为其他用户提供凭据
  • 在 C# 中,使用 Process.StartProcessStartInfo.这让您可以提供流程运行所依据的凭据
  • Windows 服务需要一个帐户才能运行 - 这可以是与已登录用户不同的用户(无论是否有人登录都会运行)
  • Use runas, supplying the credentials for the other user
  • In C#, use Process.Start with ProcessStartInfo. This lets you provide the credentials under which the process should run
  • Windows services require an account to run - this can be a different user than the logged in one (and will run whether someone is logged on or not)

您不能更改已经正在运行的进程的凭据.

You can't change the credentials of an already running process.

你能准确地解释你想要达到的目标吗?也许还有其他方法可以实现您想要的.

Can you explain exactly what you are trying to achieve? Perhaps there are other ways to achieve what you want.