ExitWindowsEx貌似只能针对所有活动的,而我想只针对指定用户,不要说logoff,调用cmd有点悲催。。提前谢过大家!

解决方案 »

  1.   

    用WTSLogoffSession即可.The WTSLogoffSession function logs off a specified Terminal Services session.
    BOOL WTSLogoffSession(
      HANDLE hServer,
      DWORD SessionId,
      BOOL bWait
    );Parameters
    hServer  
    [in] Handle to a terminal server. Specify a handle opened by the WTSOpenServer function, or specify WTS_CURRENT_SERVER_HANDLE to indicate the terminal server on which your application is running.  
    SessionId  
    [in] A Terminal Services session identifier. To indicate the current session, specify WTS_CURRENT_SESSION. You can use the WTSEnumerateSessions function to retrieve the identifiers of all sessions on a specified terminal server.  
    To be able to log off another user's session, you need to have the Reset permission. For more information, see Terminal Services Permissions. To modify permissions on a session, use the Terminal Services Configuration administrative tool.bWait  
    [in] Indicates whether the operation is synchronous.  
    If bWait is TRUE, the function returns when the session is logged off.If bWait is FALSE, the function returns immediately. To verify that the session has been logged off, specify the session identifier in a call to the WTSQuerySessionInformation function. WTSQuerySessionInformation returns zero if the session is logged off.