显示SwitchUser屏幕

时间:2012-12-29 08:45:57

标签: c# windows winforms customization user-customization

我正在开发一个应用程序来切换Windows 7的切换用户和登录屏幕。

我的应用程序是作为向导构建的,最后一步是dn,我希望用户能够通过按下按钮来查看切换用户屏幕,就像他/她在开始菜单中所做的那样:

enter image description here

1 个答案:

答案 0 :(得分:1)

取自Shortcut to Switch User in Windows Vista

using System;
using System.Runtime.InteropServices;
using System.ComponentModel;

class Program
{
  [DllImport("wtsapi32.dll", SetLastError = true)]
  static extern bool WTSDisconnectSession(IntPtr hServer, int sessionId, bool bWait);

  const int WTS_CURRENT_SESSION = -1;
  static readonly IntPtr WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero;

  static void Main(string[] args)
  {
    if (!WTSDisconnectSession(WTS_CURRENT_SERVER_HANDLE,
         WTS_CURRENT_SESSION, false))
      throw new Win32Exception();
  }
}